這很可能出現之前,但下面的代碼是從我正在修改的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