문제

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.

도움이 되었습니까?

해결책

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

e.ChosenPhoto.Seek(0, System.IO.SeekOrigin.Begin);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top