Use MediaCapture on a Windows 8 desktop app

后端 未结 3 1285
甜味超标
甜味超标 2021-01-02 18:57

On a Windows 8 desktop app, I need to take a photo using the camera in C# 4.5.

I\'ve tried to use the CameraCaptureUI class, but it is not available on a desktop app

相关标签:
3条回答
  • 2021-01-02 19:11

    Late reply, but in case that helps folks in the future: previewing MediaCapture in WPF can be done via D3DImage and some native interop (create a custom Media Foundation Sink, grab DirectX 11 textures, convert them to DirectX 9). It is a bit of code but can be encapsulated so it is still simple to call from C#. Here is some code sample: https://github.com/mmaitre314/MediaCaptureWPF

    0 讨论(0)
  • 2021-01-02 19:12

    Unfortunately, I cannot use a CaptureElement on a non store app. Is there another component that I >can use in a WPF or WinForm app, to be able to show the preview of the camera ?

    For a solution to using something similar to CaptureElement in a non-WinRT application, I've found this: http://wpfcap.codeplex.com/

    I have used it on a wpf control hosted in a Windows forms app and had no problems. Only that I had to keep using MediaCapture to capture photos and I'm also having the problem of the pictures too dark on the tablet (ok on pc). It seems that calling capture.CapturePhotoToStreamAsync sincronously takes the photo as you see it on the preview.

    0 讨论(0)
  • 2021-01-02 19:32

    After the picture is taken I do the following:

    _ms.Seek(0);
    var _bmp = new BitmapImage();
    _bmp.SetSource(_ms);
    preview1.Source = _bmp;
    

    The preview XAML control is

    <Image x:Name="preview1" Margin="850,90,102,362" />
    
    0 讨论(0)
提交回复
热议问题