代码如下
//有用的API函数
size_t width = CVPixelBufferGetWidth(pixelBuffer);
size_t height = CVPixelBufferGetHeight(pixelBuffer);
OSType pixeltype = CVPixelBufferGetPixelFormatType(pixelBuffer);
bool isPlanar = CVPixelBufferIsPlanar(pixelBuffer);
size_t planeCount = CVPixelBufferGetPlaneCount(pixelBuffer);
//必须做这一步
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
//可选了解的地址计算函数
uint8_t * mainBaseAddress = (uint8_t*)CVPixelBufferGetBaseAddress(pixelBuffer);
CVPlanarPixelBufferInfo_YCbCrBiPlanar *yDestPlaneInfo = (CVPlanarPixelBufferInfo_YCbCrBiPlanar*)mainBaseAddress;
int32_t Y_offset_to_base = yDestPlaneInfo->componentInfoY.offset;
//必须使用的地址计算函数
size_t Y_bytes_per_row = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer,0);
uint8_t * baseAddress = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
// use this base address to access C-array style pixel values
// must use Y_bytes_per_row as image width (for memory aligning purpose).
//在此修改pixel数值(115,120)为128;
baseAddress[115*Y_bytes_per_row + 120] = 128;
//必须做这一步
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
版权声明:本文为u010469993原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。