Domanda

I need to save the photo that was captured with the CameraCaptureTask, in the Media Library of the phone, and at the same time I want to show this photo in an Image control. The thing is that I first try to rotate the image by accessing its Exif data, so as it appears with the correct orientation in the Image control.

private void cameraTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            int angle = GetAngleFromExif(e.ChosenPhoto);
            WriteableBitmap currentImage = DecodeImage(e.ChosenPhoto, angle);
            photoImage.Source = currentImage;

            MediaLibrary medialibrary = new MediaLibrary();
            medialibrary.SavePicture("test.jpg", e.ChosenPhoto);
        }
    }

The code crashes in the last line, with the error:

Value does not fall within the expected range.

What is possibly going wrong here?

Thank you in advance.

È stato utile?

Soluzione

Before calling the SavePicture method, you should set the Stream back at the beginning, like this:

e.ChosenPhoto.Seek(0, System.IO.SeekOrigin.Begin);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top