Reputation: 1369
I have followed this article here: http://blogs.msdn.com/b/eternalcoding/archive/2013/10/29/how-to-use-specific-winrt-api-from-desktop-apps-capturing-a-photo-using-your-webcam-into-a-wpf-app.aspx
And it all works great... but how do I get a preview in WPF?
The XAML "CaptureElement" control is not available in WPF. Is there any other way I can get a preview using the MediaCapture API?
Why would Microsoft not make this control Available?
Upvotes: 1
Views: 2727
Reputation: 522
Late reply, but in case that helps folks in the future: previewing MediaCapture in WPF is difficult but possible. Here is some code sample: https://github.com/mmaitre314/MediaCaptureWPF
Upvotes: 4
Reputation: 1369
After investigating further it seems impossible to get this to work with the XAML Capture Element or any other XAML element in WPF.
I decided to port my WPF app to a Win8 application. I kept the existing back end code and referenced it using a Brokered WinRT Component. An excellent tutorial can be found here: http://devhawk.net/2014/04/25/brokered-winrt-components-step-one/ on how to create a WinRT brokered component.
Keep in mind that the app must be sideloaded and will not work for apps that you want to publish to the store.
Upvotes: 1
Reputation: 25623
You will have to rig up a mechanism to display the converted BitmapImage
yourself, e.g., either in an Image
control or as an ImageBrush
on some surface. To the best of my knowledge, WinRT controls cannot be hosted in WPF.
CaptureElement
was presumably not ported to WPF because it depends on WinRT APIs, and it makes little sense to introduce a dependency into WPF for an API that is only available on Windows 8+, and which is only officially supported in Windows Store apps.
Upvotes: 0