Edit image file problem. RRS feed

  • Question

  • I'm doing a testbed based on MS sample 'Media capture using webcam sample' to modify the captured image file automatically.

    When I got the interface IRandomAccessStream in 'OnPhotoFileOpenedComplete', How to modify the image buffer which stored in IRandomAccessStream?

    My code is the following, but it does not work:

    WriteableBitmap^ bmpimg = ref new WriteableBitmap(width,height);

    IBuffer^ iBuffer = bmpimg->PixelBuffer;

    IUnknown* pUnk = reinterpret_cast<IUnknown*>(iBuffer);
    IBufferInternal* pBufferInternal = nullptr;
    HRESULT hr = pUnk->QueryInterface(IID_IBufferInternal, (void**)&pBufferInternal);

    BYTE* pTempBuffer = NULL;

    //modify the pTempBuffer which contains BGRA for each pixel



    It seems that pTempBuffer does not contain image data.

    Anyone can give me some suggestion? Thank you.

    Thursday, May 31, 2012 3:00 PM

All replies

  • Hi vtshe,

    Are you trying to read the data without displaying it or do you also want to display it?

    I don't believe the WritableBitmap will load its pixels unless it's in the visible tree, so the bits won't be present in your case. If you don't want to display this you can decode the pixels with a BitmapDecoder instead.

    Also please use the documented IID_IBufferByteAccess interface instead of IID_IBufferInternal. If IID_IBufferInternal is defined the same as IID_IBufferByteAccess then it should work, but defining it yourself is more complicated and prone to error.


    Thursday, May 31, 2012 3:40 PM
  • Hi, Rob,

    You have posted some C# code in another thread 'http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/824eca30-bbc0-4bc4-8989-855e4a68bfe6'.

    How to implement the same in C++?

    Thank you.

    Friday, June 1, 2012 12:52 AM