gpt4 book ai didi

c++ - 从 Windows::Storage::Streams::IBuffer 中获取字节数组

转载 作者:IT老高 更新时间:2023-10-28 22:33:00 27 4
gpt4 key购买 nike

我有一个实现接口(interface) Windows::Storage::Streams::IBuffer 的对象,我想从中获取一个字节数组,但是在查看该接口(interface)的文档时看起来毫无用处,并且文档没有提供对可以与此接口(interface)结合以实现我的目的的任何其他类的任何引用。到目前为止,我在 google 上找到的只是对 .Net 类 WindowsRuntimeBufferExtensions 的引用。但我使用的是 C++,所以这也是一个死胡同。

有人可以提示如何在 C++ 中从 Windows::Storage::Streams::IBuffer 获取字节数组吗?

最佳答案

您可以通过奇异的 COM 强制转换来使用 IBufferByteAccess:

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 复制的代码示例

关于c++ - 从 Windows::Storage::Streams::IBuffer 中获取字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11853838/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com