我正在尝试从媒体库中裁剪图像.我可以访问图像,启动默认裁剪工具甚至保存裁剪的图像结果.但是,如果裁剪成功,我正在使用的意图将不会返回任何结果.
- 主要方法 -
// Crop photo intent.
Intent intent = new Intent("com.android.camera.action.CROP", null);
intent.setData(uri);
intent.putExtra("outputX", outputX);
intent.putExtra("outputY", outputY);
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra("scale", scale);
intent.putExtra("return-data", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, createTempCroppedImageFile());
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
// Publish intent to crop picture.
activity.startActivityForResult(intent, activity.CROP_PHOTO_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
- OnActivityResult()方法 -
// Photo crop activity.
if (requestCode == CROP_PHOTO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.d(TAG, "user cropped a photo");
signupScreen.setImage(new PhotoTool(this).getTempCroppedImageFileLocation());
} else
Log.d(TAG, "user cancelled photo crop");
}
Run Code Online (Sandbox Code Playgroud)
-
如果我取消了裁剪活动,我会成功获得"用户取消的照片裁剪"消息.但是,如果我裁剪图像,新裁剪的图像将出现在目标目录中,但OnActivityResult()函数永远不会被调用.是什么赋予了??
看看LogCat,我发现每次保存裁剪的图像时,"JavaBinder"都会抱怨"Binding Transaction失败".我知道这与记忆有某种关系.但裁剪文件的大小只有24KB.嗯.
android android-intent android-image onactivityresult android-crop