locked
How to Display a MediaCapture image acquired in a Standard assembly in a WPF Framework Image control? RRS feed

  • Question

  • The basic problem to solve is making MediaCapture, a UWP library item, related services available to WPF/MVVM/Framework applications without generating compile time cross platform warnings. I've been approaching that by writing a class in the Standard library that exposes public properties of types that a Framework application can directly access. The latest problem (of many) is how to display an acquired photo in a WPF Image control. I'm having trouble converting the acquired image format converted into something that can be displayed in a WPF Image control. As a possible alternative, I wouldn't be adverse to putting a ContentControl in the WPF View and then attaching a MediaCapture compliant control inside it as long as that can be accomplished in a WPF/MVVM compliant basis (read: Code behind is evidence of demonic influence. Bad programmer. No hyper caffeinated sugar beverage.).

    There is a button whose Command is handled in the WPF ViewModel. It makes a call into 

    public async void SnapAsync()
    {
        LowLagPhotoCapture lowLagCapture = await MediaCaptureMgr.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8));
        CapturedPhoto capturedPhoto = await lowLagCapture.CaptureAsync();
        SoftwareBitmap softwareBitmap = capturedPhoto.Frame.SoftwareBitmap;
    
        // Missing code here - how to make the convertion to 
        // an ImageSource or some other bitmap format that an Image.Source will accept.
        CurrentImage = ????;
    
        // Release resources now that the capture is done.
        await lowLagCapture.FinishAsync();
    }
    


    Richard Lewis Haggard

    Monday, September 7, 2020 6:30 PM

All replies

  • Hi Richard.Haggard,

    Thank you for posting here.

    According to your description, your issue is more related to WPF. Therefore, it will be more appropriate to ask your question in Q&A / WPF forum.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 8, 2020 2:18 AM