0

So I wanted to use the UWP MediaCapture in my WPF application as shown in this example. The only difference is, that I need a BitmapImage from WPF as output instead of a file or UI.XAML BitmapImage.

I've already tried multiple things which didnt quite bring me to what I need, such as the following which converts the InMemoryRandomAccessStream into a UI.XAML BitmapImage from UWP.

using var stream = new InMemoryRandomAccessStream();

await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
stream.Seek(0);

var source = new BitmapImage();
await source.SetSourceAsync(stream);

As an alternative converting the UI.XAML BitmapImage into a Windows.Media BitmapImage would also work.

LYCRIs
  • 40
  • 8
  • With a WPF BitmaImage you should be able to set `source.Stream = stream.AsStream();`. Besides that, you are calling `ImageEncodingProperties.CreateJpeg()` twice. – Clemens Mar 22 '23 at 16:35
  • @Clemens I've already tried that before, but it doesnt seem to work. I guess it not working is caused by the "image collection" being asyncronous and I guess there must be some kind of problem with that. For the CreateJpeg Part, yeah I had it twice, forgot to delete that part and didnt notice it, thank you for mentioning. – LYCRIs Mar 23 '23 at 14:02

0 Answers0