Using WinRT library in WPF application.

不羁岁月 提交于 2019-12-04 05:21:37

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/26633100/using-winrt-library-in-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!