0

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.

Mihai
  • 39
  • 1
  • 10

1 Answers1

0
        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.

Pedro G. Dias
  • 3,162
  • 1
  • 18
  • 30
  • Ok, I get it. But how can I save them in camera roll, like whats app for example, not to create my own file – Mihai Mar 24 '16 at 16:13
  • Aah, yeah, get special folder from UWP, you can see in my example, the file that I am creating is saved in Windows.Storage.KnownFolders.PicturesLibrary, which is the pictures folder. from there, you should not have a big problem finding the camera roll, which is a subfolder. – Pedro G. Dias Mar 24 '16 at 16:14
  • I will try your code and I will let you know. Thanks in advice @Pedro! – Mihai Mar 24 '16 at 16:21
  • Good luck - don't forget to initialize your MediaCapture. I did it like so: _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(); _imageEncodingProperties = ImageEncodingProperties.CreateJpeg(); – Pedro G. Dias Mar 24 '16 at 16:22
  • can you look over my app? [link](https://onedrive.live.com/redir?resid=861467A1111C7105!7235&authkey=!AIbXe5pqhB9IrrY&ithint=file%2crar) The photo saved is not good. Can you tell me where is the problem? – Mihai Mar 25 '16 at 09:34