Android image crop URI exception

First of all, I am using xamarin, but the problem is the same on the local java project. I updated the SDK to 5.1 and encountered a strange error in the working code 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);
            }

ImageStream ist is the path to the file. The image cutter itself works well. However, when I click 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

I can't find a method similar to android.net.uri.parse in the mediastore or mediastore.image namespace. Does this mean that I must first save the image to mediastore and then retrieve it before calling the intention? Or is there an obvious solution I missed at all?

Cheers, Tom

resolvent:

Well, it seems that I really miss the content here and expand the URI retrieval code to put the image into the media storage 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);

If you can, I think it may be a bit too correct. But at least it can solve the problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>