locked
How do you get the pixel data from a BitmapSource object in WinRT C++ / CX?

    Question

  • I have a BitmapSource, and I need to read / copy the pixel values.  In .NET and Silverlight, I was converting to WriteableBitmap using the constructor that takes BitmapSource.  In WinRT, how can I achieve the same functionality?
    Monday, June 4, 2012 4:10 PM

Answers

  • Hi xcRacer,

    You will need to remember the original source of your bitmap to extract the pixels. Once they are in the BitmapSource there is no way to extract just the pixels. Depending on your needs you may remember the location (uri, file path) or you may want to load them into a WriteableBitmap originally and then store that as well as loading that into your ImageSource.

    --Rob

    Monday, June 4, 2012 8:34 PM
    Owner

All replies

  • Hi xcRacer,

    You will need to remember the original source of your bitmap to extract the pixels. Once they are in the BitmapSource there is no way to extract just the pixels. Depending on your needs you may remember the location (uri, file path) or you may want to load them into a WriteableBitmap originally and then store that as well as loading that into your ImageSource.

    --Rob

    Monday, June 4, 2012 8:34 PM
    Owner
  • That's not really acceptable for me.  I'm creating an imaging toolkit.  I have to be flexible with the input that my methods take.  Are you telling my that for my WinRT / Metro version, I can only accept WriteableBitmap as input?

    Monday, June 4, 2012 8:42 PM
  • Hi xcRacer,

    We understand that this isn't ideal for many scenarios, but there isn't any way to get the pixels out of a BitmapSource. You can get the pixels out of a WriteableBitmap or you can otherwise keep ahold of the original source of the bitmap (URI, file, stream, etc.) so you can reacquire the pixels.

    Your toolkit does not have to accept a WriteableBitmap as input, but if it wants to be able to edit the pixels then it needs to accept input at a pixel addressable level. I would look into accepting a byte array or stream rather than a higher level container. This could be extracted from a WriteableBitmap or from a BitmapDecoder. You could also accept a file or URI and then decode it inside your toolkit. Ultimately, you will need to determine what works best for your specific scenario.

    --Rob

    Monday, June 4, 2012 10:12 PM
    Owner
  • Just so you understand, it is not a question if what works best for my situation, it is what would work best for my customer.  So, I'll stick with offering just WritableBitmap as input.

    I hope Microsoft sees that this is a step backwards and addresses it in the future.

    Monday, June 4, 2012 11:07 PM