从 Windows::Storage::Streams::IBuffer 中获取字节数组
我有一个实现接口 Windows::Storage::Streams::IBuffer
的对象,我想从中获取一个字节数组,但是在查看此接口的文档时看起来很没用,并且文档没有提供对可以与此接口结合以实现我的目的的任何其他类的任何参考.到目前为止,我在谷歌上发现的所有内容都是对 .Net 类的引用 WindowsRuntimeBufferExtensions 但我使用的是 C++ 所以这也是一个死胡同.
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 documentation this interface looks pretty useless, and the documentation does not offer any reference to any other class that could be combined with this interface to achieve my purpose. All I have found so far with google is a reference to the .Net class WindowsRuntimeBufferExtensions but I am using C++ so this is also a dead end.
有人可以提示一下如何从 C++ 中的 Windows::Storage::Streams::IBuffer
获取字节数组吗?
Can someone give a hint on how to get an array of bytes from Windows::Storage::Streams::IBuffer
in C++?
推荐答案
您可以使用 IBufferByteAccess,通过异国情调的 COM 转换:
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<IInspectable> insp(reinterpret_cast<IInspectable*>(obj));
// Query the IBufferByteAccess interface.
ComPtr<IBufferByteAccess> bufferByteAccess;
ThrowIfFailed(insp.As(&bufferByteAccess));
// Retrieve the buffer data.
byte* pixels = nullptr;
ThrowIfFailed(bufferByteAccess->Buffer(&pixels));
return pixels;
}
从 http://cm-bloggers 复制的代码示例.blogspot.fi/2012/09/accessing-image-pixel-data-in-ccx.html
相关文章