Android的图像裁剪乌里异常 [英] Android Image Crop Uri Exception
问题描述
先上去,我使用Xamarin,但问题是在本地Java项目相同的。
我更新SDK 5.1和遇到的code一个奇怪的错误,以前工作的罚款。
first up, I am using Xamarin, but the problem is the same on a native Java project. I was updating the SDK to 5.1 and encountered a strange error on code that worked fine before.
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);
}
IST的ImageStream该文件的路径。图像割草机自身加载了罚款和作品。然而,当我打救我得到的logcat以下异常:
imageStream ist the file's path. The image cropper itself load up fine and works. However when I hit save I get the following exception in 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,然后调用的意图之前找回?还是有一个明显的解决方案,我只是错过了吗?
I didn't find a similar method to the Android.Net.Uri.Parse in the MediaStore or MediaStore.Image namespaces. Does this mean I would first have to save the image to MediaStore and then retrieve it before calling the intent? Or is there an obvious solution which I simply missed?
干杯
汤姆
推荐答案
好吧,看来我真的错过了一些东西在这里,延长了code的URI检索放像进入媒体商店第一。
Ok it seems I really missed something here, extended the code for the uri retrieval to put the image into the media store first.
var file = new Java.IO.File(imageStream);
var bmp = BitmapFactory.DecodeFile(file.AbsolutePath);
img = MediaStore.Images.Media.InsertImage(ContentResolver, bmp, "" ,"");
var fileUri = Android.Net.Uri.Parse(img);
我喜欢这种感觉,也许矫枉过正,如果可以随意发表评论。但至少它解决了问题。
I feel like this maybe overkill, if so feel free to comment. But at least it solves the issue.
这篇关于Android的图像裁剪乌里异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!