Hi, 大家周末愉快!
羊了仍在苦苦debug的码农,请教安卓DX一个问题,在app中调用 CROP intent裁剪照片,调用无效!LogCat中也没有什么线索。而拍照生成照片没问题。
主要代码如下:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
intent.setData(mImageCaptureUri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
intent.putExtra("outputX", 480);
intent.putExtra("outputY", 480);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCropUri);
intent.putExtra("crop", "true");
intent.putExtra("return-data", false);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
startActivityForResult(intent, CROP_FROM_CAMERA);
其中:
- 是在安卓虚拟机上测试,确定有裁剪功能。因为照相后可以简单编辑。API Level 是31. 难道31上不能intent调用CROP了吗?
- 原始照片是从相册 Downloads 下,选取的一个JPG文件。
mImageCaptureUri = content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F71/ORIGINAL/NONE/image%2Fpng/1987893059 - 目的照片app代码已经在调用裁剪intent之前生成好了,大小为0字节,等待填充。
mImageCropUri = content://com.myapp.fileprovider/my_pic/Pictures/tmp_kuilimar_16712596169354514375851720661420.jpg
谢谢大家!