locked
[UWP][VB]View Pixels of a SoftwareBitmap RRS feed

  • Question

  • I have a SoftwareBitmap obtained from MediaCapture, and I would like to view the individual pixels. How do I do this? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Tuesday, June 19, 2018 7:55 PM

All replies

  • Hello,

    Read SoftwareBitmap first: Use CopyToBuffer and CopyFromBuffer to copy pixel data back and forth between a SoftwareBitmap and the PixelBuffer of a WriteableBitmap.

    Then see WriteableBitmap

    The image source data of a WriteableBitmap is an underlying pixel buffer. WriteableBitmap.PixelBuffer cannot be written to directly, however, you can use language-specific techniques to access the buffer and change its contents.
    To access the pixel content from C# or Microsoft Visual Basic, you can use the AsStream extension method to access the underlying buffer as a stream.

    And to specific pixel, see the answer from this thread: https://social.msdn.microsoft.com/Forums/en-US/6b7a7beb-0e18-484f-8e9c-5fad3482485d/uwp-bitmap-class-access-raw-pixel-data?forum=wpdevelop 

    Where Rob has provided the answer for how to caculate the a pixel's position in the array. And here you can find a sample.

    Best regards,

    Barry


    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.

    Thursday, June 21, 2018 2:52 AM
  • Hi Nathan,

    If you just want to display the video on the screen you should use the XAML CaptureElement to video the video. The only reason that you should be getting a bitmap from the MediaCature directly is if you want to manipulate the bits in some way. If you do plan to manipulate the video you should be using a video effect rather than trying to manipulate the buffer directly.

    CaptureElement
    https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.CaptureElement

    Effects for video capture
    https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/effects-for-video-capture

    Custom video effects
    https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/custom-video-effects

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    • Proposed as answer by Barry Wang Thursday, June 28, 2018 9:03 AM
    Friday, June 22, 2018 9:23 PM