locked
Using WriteableBitmap in C++

    Question

  • I'm able to load a photo into a WriteableBitmap and display it. I'm then able to get the pixel data from the WriteableBitmap and alter it. However, I'm struggling with replacing the pixel data in the WriteableBitmap and displaying the altered data. 

    Can someone please provide a source code example of modifying pixel data in a WriteableBitmap, in C++, rather than just referring to an API?

    Thanks in advance,

    Dave

    Wednesday, May 30, 2012 1:03 PM

Answers

  • Problem solved. I've abandoned the DataReader/DataWriter approach and altered the pixel data in-place.
    • Marked as answer by Jesse Jiang Thursday, May 31, 2012 6:34 AM
    Wednesday, May 30, 2012 3:59 PM

All replies

  • I've been using a DataReader to get the pixel data from the WriteableBitmap:

        auto buffer = m_image->PixelBuffer;  
        int height = m_image->PixelHeight;
        int width = m_image->PixelWidth;
        auto pixels = ref new Array<unsigned char>((height * width) * 4);
        auto reader = DataReader::FromBuffer(buffer);
        reader->ReadBytes(pixels);

    This seems to work well, with my pixels array containing the image pixel data. However, my attempts to use a DataWriter to write altered pixel data back to the WriteableBitmap are getting nowhere. Any advice?

    Dave

    Wednesday, May 30, 2012 3:07 PM
  • Problem solved. I've abandoned the DataReader/DataWriter approach and altered the pixel data in-place.
    • Marked as answer by Jesse Jiang Thursday, May 31, 2012 6:34 AM
    Wednesday, May 30, 2012 3:59 PM
  •  

    Thanks for sharing the solution.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 31, 2012 6:35 AM
  • Can you post the full code solution without the DataReader/DataWriter portion? Thanks!

    Thursday, June 28, 2012 9:44 PM