0
我正在使用相機功能Capture
圖像從不同的按鈕2次。捕獲的圖像後,它會去Crop
選項,用戶可以裁剪圖像。它也工作正常。
但是,現在的問題是,當用戶捕獲第二個圖像,然後應用程序重定向到Crop
圖像,只顯示第一個圖像,而不是第二個捕獲圖像。我將其設置爲ImageView
之後刪除圖像。不知道什麼是錯的?
請幫我解決這個問題。
我的代碼:使用Android的捕獲圖像裁剪圖像問題
Bitmap bm_PhotoProof = null;
Bitmap bm_AddressProof = null;
private static final String TEMP_PHOTO_FILE = "tmp_ihis.jpg";
private static final int REQ_CODE_PICK_IMAGE_PHOTOPROOF = 0;
private static final int REQ_CODE_PICK_IMAGE_ADDRESSPROOF = 1;
imgPhotoProof.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
cameraIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(cameraIntent,
REQ_CODE_PICK_IMAGE_PHOTOPROOF);
}
});
imgAddressProof.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
cameraIntent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(cameraIntent,
REQ_CODE_PICK_IMAGE_ADDRESSPROOF);
}
});
private Uri getTempUri() {
return Uri.fromFile(getTempFile());
}
private File getTempFile() {
File f = new File(Environment.getExternalStorageDirectory(),
TEMP_PHOTO_FILE);
try {
f.createNewFile();
} catch (IOException e) {
Log.e("getTempFile()->", e.getMessage().toString());
}
return f;
}
public void cropCapturedImage(Uri picUri, String Type) {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 0);
cropIntent.putExtra("aspectY", 0);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
if (Type.equals("Photo")) {
startActivityForResult(cropIntent, 5);
} else {
startActivityForResult(cropIntent, 6);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQ_CODE_PICK_IMAGE_PHOTOPROOF) {
File tempFile = getTempFile();
cropCapturedImage(Uri.fromFile(tempFile), "Photo");
} else if (requestCode == REQ_CODE_PICK_IMAGE_ADDRESSPROOF) {
File tempFile = getTempFile();
cropCapturedImage(Uri.fromFile(tempFile), "Address");
}
if (resultCode != Activity.RESULT_CANCELED) {
if (requestCode == 5) {
if (data != null) {
Bundle extras = data.getExtras();
bm_PhotoProof = extras.getParcelable("data");
}
imgPhotoProof_Pic.setImageBitmap(bm_PhotoProof);
File tempFile = getTempFile();
if (tempFile.exists()) {
tempFile.delete();
}
}
if (requestCode == 6) {
if (data != null) {
Bundle extras = data.getExtras();
bm_AddressProof = extras.getParcelable("data");
}
imgAddressProof_Pic.setImageBitmap(bm_AddressProof);
File tempFile = getTempFile();
if (tempFile.exists()) {
tempFile.delete();
}
}
}
}
}
Android不具備''CROP' Intent':http://commonsware.com/blog/2013/01/23/no-android-不 - 不具備的,作物intent.html – CommonsWare 2014-09-27 12:16:05