3
首先,我使用Xamarin,但问题与原生Java项目相同。 我正在更新SDK到5.1,并遇到一个奇怪的错误,以前工作正常的代码。Android Image裁剪Uri异常
imageStream = "file://" + imageStream;
Mvx.Trace("path: " + imageStream);
img = imageStream;
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
var fileUri = Android.Net.Uri.Parse(imageStream);
cropIntent.SetDataAndType(fileUri, "image/*");
// set crop properties
cropIntent.PutExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.PutExtra("aspectX", 5);
cropIntent.PutExtra("aspectY", 4);
// indicate output X and Y
cropIntent.PutExtra("outputX", 1000);
cropIntent.PutExtra("outputY", 800);
// retrieve data on return
cropIntent.PutExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
StartActivityForResult(cropIntent, PIC_CROP);
}
imageStream是文件的路径。图像裁剪本身加载正常,并工作。然而,当我点击保存,我得到以下异常中的logcat:
E/AndroidRuntime(5333): FATAL EXCEPTION: BackgroundTask #1
E/AndroidRuntime(5333): Process: com.google.android.apps.photos, PID: 5333
E/AndroidRuntime(5333): java.lang.IllegalArgumentException: mediaStoreUri must be a MediaStore Uri
我没有找到在MediaStore或MediaStore.Image命名空间类似的方法将Android.Net.Uri.Parse。这是否意味着我首先必须将图像保存到MediaStore,然后在调用意图之前检索它?还是有一个明显的解决方案,我只是错过了?
干杯 汤姆
我在Android 6上有同样的例外。MediaStore.Images.Media.InsertImage修复了我的裁剪!谢谢你的文章! 虽然这很奇怪......似乎是M中的一个bug。 –