Getting an array of bytes out of Windows::Storage::Streams::IBuffer

后端 未结 7 1282
囚心锁ツ
囚心锁ツ 2020-12-01 11:22

I have an object that implements the interface Windows::Storage::Streams::IBuffer, and I want to get an array of bytes out of it, however while looking at the d

7条回答
  •  自闭症患者
    2020-12-01 11:59

    You can use IBufferByteAccess, through exotic COM casts:

    byte* GetPointerToPixelData(IBuffer^ buffer)
    {
       // Cast to Object^, then to its underlying IInspectable interface.
    
       Object^ obj = buffer;
       ComPtr insp(reinterpret_cast(obj));
    
       // Query the IBufferByteAccess interface.
       ComPtr bufferByteAccess;
       ThrowIfFailed(insp.As(&bufferByteAccess));
    
       // Retrieve the buffer data.
    
       byte* pixels = nullptr;
       ThrowIfFailed(bufferByteAccess->Buffer(&pixels));
    
       return pixels;
    
    }
    

    Code sample copied from http://cm-bloggers.blogspot.fi/2012/09/accessing-image-pixel-data-in-ccx.html

提交回复
热议问题