我想从相册中选择图片或使用相机拍摄照片。 如果我将图片加载到imageView中,然后点击确认按钮,如何保存该图片? 我需要使用saveState()吗? 请发表一些评论。 谢谢。
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) return;
switch (requestCode)
{
case PICK_FROM_CAMERA:
Bitmap selectedImage = (Bitmap) data.getExtras().get("data");
selectedImage = Bitmap.createScaledBitmap(selectedImage, 80, 80, false);
mImageView.setImageBitmap(selectedImage);
break;
case PICK_FROM_GALLERY:
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
mImageView.setImageURI(selectedImageUri);
break;
}
}
private void saveState()
{
String name = (String) nameEdit.getText().toString();
String category = (String) categoryEdit.getText().toString();
String expired_date = (String) expired_Date_Btn.getText().toString();
ImageView image = (ImageView) mImageView.setImageURI(); //how to edit?
if(mRowId == null)
{
long id = mDbHelper.insertItem(category, name, expired_date);
if(id>0)
{
mRowId = id;
}
}
else
{
mDbHelper.updateItem(mRowId, category, name, expired_date);
}
}
//How can I save image after clicking button?
confirmButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v){
setResult(RESULT_OK);
finish();
}
});