这很可能出现之前,但下面的代码是从我正在修改的MSDN示例中获取的。我想知道如何遍历包含有关位图数据的缓冲区内容并打印出颜色。每个像素是4个字节的数据,所以我假设R G B值占这些字节中的3个,并且可能A是第四个。读取媒体缓冲区 - 指针运算C++语法
所需的指针算术(理想情况下在一个循环中)的C++语法是什么,它将在迭代过程中指向的值存储到我可以使用的局部变量中,例如。打印到控制台。
非常感谢
PS。这安全吗?还是有更安全的方式来读取IMFMediaBuffer的内容?我找不到替代品。
下面是代码:
hr = pSample->ConvertToContiguousBuffer(&pBuffer); // this is the BitmapData
// Converts a sample with multiple buffers into a sample with a single IMFMediaBuffer which we Lock in memory next...
// IMFMediaBuffer represents a block of memory that contains media data
hr = pBuffer->Lock(&pBitmapData, NULL, &cbBitmapData); // pBuffer is IMFMediaBuffer
/* Lock method gives the caller access to the memory in the buffer, for reading or writing:
pBitmapData - receives a pointer to start of buffer
NULL - receives the maximum amount of data that can be written to the buffer. This parameter can be NULL.
cbBitmapData - receives the length of the valid data in the buffer, in bytes. This parameter can be NULL.
*/
我不熟悉IMFMediaBuffer,但[MSDN](http://msdn.microsoft.com/en-us/library/ms696261/(v = vs.85 \).aspx)说:“如果缓冲区包含二维图像数据(例如未压缩的视频帧),您应该查询IMF2DBuffer接口的缓冲区,IMF2DBuffer上的方法针对二维数据进行了优化。“ – user786653
感谢您花时间回复。正如你通过我发布自己的答案所看到的,我使用你期望的指针算法解决了这个问题,所以Media Buffer可以像内存中的其他数组一样对待 – ComethTheNerd