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 中获取字节数组
基础教程推荐
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
