How to get ImageStream from MediaCapture?

477 views Asked by At

In WP 8 I used PhotoCamera to make a camera app and to save the image in camera roll I used this method:

private void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
    string fileName = "photo.jpg";
    MediaLibrary library = new MediaLibrary();
    library.SavePictureToCameraRoll(fileName, e.ImageStream);
}

In WPSL 8.1 I use MediaCapture and I use the same style to save image in camera roll but I don't know how to retrieve ImageStream from MediaCapture like in e.ImageStream. I am open to suggestions even with other programming style for saving to camera roll.

1

There are 1 answers

5
Pedro G. Dias On
        var file = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(IMAGECAPTURE_FILENAME, Windows.Storage.CreationCollisionOption.ReplaceExisting);

        await _exceptionHandler.Run(async () =>
        {
            await _mediaCapture.CapturePhotoToStorageFileAsync(_imageEncodingProperties, file);
            var photoStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            await bitmap.SetSourceAsync(photoStream);
        });

The above is taken from a UWP app to save an image to storage, then read it from disk as a stream. I've never been able to capture the image directly as a stream.