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

后端 未结 7 1288
囚心锁ツ
囚心锁ツ 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 12:05

    Since this question is tagged c++, here's a solution using C++/WinRT. It essentially does the same as this answer under the hood, but is way more accessible. The (undocumented) data() helper on the IBuffer projection does all the heavy lifting:

    uint8_t* GetPointerToPixelData(::winrt::Windows::Storage::Streams::IBuffer const& buffer)
    {
        return buffer.data();
    }
    

    There is unfortunately no official documentation (yet), and I only stumbled across this in the sample code for the WritableBitmap.PixelBuffer property (make sure to select "C++/WinRT" from the language dropdown at the top right).

    An identical solution (querying for the IBufferByteAccess interface) is also available from that documentation entry when selecting "C++/CX" from the language dropdown.

提交回复
热议问题