Getting an array of bytes out of Windows::Storage::Streams::IBuffer(从 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
这篇关于从 Windows::Storage::Streams::IBuffer 中获取字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Windows::Storage::Streams::IBuffer 中获取字节数组
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
