How to get pixel bytes from ImageBrush using c++ in winRT


  • Hi,


    I am using winRT c++. I want to get pixel bytes from an ImageBrush object defined in xaml file like below. Do you know how to do this?


                <Rectangle x:Name="MyRect">
                        <ImageBrush Stretch="Fill" ImageSource="{StaticResource SampleImage}"/>






    Friday, February 03, 2012 1:24 AM


All replies

  • Hi FanZ,

    There is no way to get the pixels from the brush. The Developer Preview does not provide any way to render a Xaml element to a bitmap. You will need to get the pixels from the original image.


    Friday, February 03, 2012 3:30 AM
  • Thanks Rob! The image is embedded as a resource in assembly, do you know in which way I could get pixel bytes out of the image resource? Thanks for your help.
    Friday, February 03, 2012 6:52 PM
  • Hi Fan,

    You can load the image resource into a WriteableBitmap and then get its PixelBuffer. The hitch here is that there's an oversight in the Developer Preview such that there is no public way to access the PixelBuffer data from C++. If you search this forum for WriteableBitmap you should find more discussion of that.


    Friday, February 03, 2012 7:00 PM
  • I looked at WriteableBitmap. The msdn document says it has two constructors. One of the two takes BitmapSource as input parameter. However, when I go to dev11, only one constructor can be found, which takes two int as input. Don't know what happened. But it looks like the constructor won't help. Then I see WriteableBitmap has a method SetSource(IRandomAccessStream^ streamSource). However, it is not clear to me how this could be used. Could you give some guide?
    Friday, February 03, 2012 7:21 PM
  • The WriteableBitmap(BitmapSource) constructor is known not to work. Use the size constructor instead. To load the bitmap call SetSource with the IRandomAccessStream you get from opening your bitmap file (or wherever you have the bitmap data).



    Saturday, February 04, 2012 2:12 AM
  • In my case, 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?
    Friday, June 01, 2012 10:22 PM