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 (by explicitly querying for the IBufferByteAccess
interface) is also available from that documentation entry when selecting "C++/CX" from the language dropdown.
Update 2022-10-15
Since writing this answer the documentation has been updated. The winrt
namespace documentation now has a section called C++/WinRT functions that extend Windows Runtime APIs that lists Windows Runtime types alongside the C++/WinRT functions available in addition to the interface projections.
The IBuffer C++/WinRT extension functions link takes you to the respective section in the IBuffer
interface documentation, with the data()
function properly documented.