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

Getting an array of bytes out of Windows::Storage::Streams::IBuffer(从 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 中获取字节数组

基础教程推荐