【发布时间】:2014-04-17 14:41:18
【问题描述】:
我尝试从 sdcard 中挑选一张图片,然后对其进行裁剪。
ACTION_PICK 没问题,但是当我调用 ACTION_CROP 时,我的系统图库应用程序(我称之为 A)无法执行该操作,但另一个应用程序 (B) 可以。
我尝试了以下情况:
1/ 按 A 选择然后按 A 裁剪 => 选择 OK,裁剪失败
2/ 按 B 选择然后按 A 裁剪 => 与第一种情况相同。
3/ 按 A 挑选,然后按 B 裁剪 => 一切正常。
4/ 由 B 挑选,然后由 B 裁剪 => 一切正常。
所以我的临时结论是:我的系统应用程序无法使用我的代码执行裁剪操作(可能是我忘记了什么)。这是我的代码:
ACTION_PICK:
public Intent galleryIntent() {
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setType("image/*");
galleryIntent.putExtra("return-data", true);
return galleryIntent;
}
ACTION_CROP:
public Intent cropIntent(Uri inUri, int outputX, int outputY,
boolean isScale) {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(inUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", outputX);
cropIntent.putExtra("aspectY", outputY);
cropIntent.putExtra("outputX", outputX);
cropIntent.putExtra("outputY", outputY);
cropIntent.putExtra("scale", isScale);
cropIntent.putExtra("return-data", true);
return cropIntent;
}
我的 onActivityResult 方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_CODE_GALLERY:
imageUri = data.getData();
startActivityForResult(cropIntent(imageUri,
500, 500, true), REQUEST_CODE_CROP);
break;
case REQUEST_CODE_CROP:
Bundle extras = data.getExtras();
Bitmap tempBitmap = extras.getParcelable("data");
imgvMain.setImageBitmap(null);
imgvMain.setImageBitmap(tempBitmap);
break;
}
} else {
imageUri = null;
}
}
我错过了什么吗?
感谢您的关注!
【问题讨论】:
-
我也面临同样的问题。当我选择该应用程序进行裁剪时,图库应用程序崩溃。你应用了什么解决方案?
-
@CodeKrish 试试这个:github.com/biokys/cropimage。
如果这对你有帮助,别忘了给我的问题投票:P -
我能够找到原因并修复它,而无需创建自己的裁剪功能。我已经发布了答案。请看一看。
标签: crop android-gallery