相关疑难解决方法(0)

CVPixelBufferLockBaseAddress为什么?使用AVFoundation捕获静止图像


我正在编写一个iPhone应用程序,使用AVFoundation从相机创建静态图像.阅读编程指南我发现了一个几乎我需要做的代码,所以我试图"逆向工程"并理解它.
我发现在理解将CMSampleBuffer转换为图像的部分时遇到了一些困难.
所以这是我理解的,后来是代码.
CMSampleBuffer表示存储器中存储有附加数据的图像的缓冲区.后来我调用函数CMSampleBufferGetImageBuffer()来仅使用图像数据接收CVImageBuffer.
现在有一个我不理解的功能,我只能想象它的功能:CVPixelBufferLockBaseAddress(imageBuffer,0); 我无法理解它是否是一个"线程锁",以避免对它进行多次操作或锁定缓冲区的地址,以避免在操作期间发生变化(为什么要更改?...另一帧,不是数据被复制在另一个地方?).剩下的代码对我来说很清楚.
试图在谷歌上搜索但仍然没有找到任何帮助.
有人可以带点光吗?

-(UIImage*) getUIImageFromBuffer:(CMSampleBufferRef) sampleBuffer{

// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 

// Lock the base address of the pixel buffer 
CVPixelBufferLockBaseAddress(imageBuffer, 0); 

void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); 

// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer); 
size_t height = CVPixelBufferGetHeight(imageBuffer); 

// Create a device-dependent RGB color …
Run Code Online (Sandbox Code Playgroud)

iphone image capture avfoundation ios4

7
推荐指数
1
解决办法
6941
查看次数

标签 统计

avfoundation ×1

capture ×1

image ×1

ios4 ×1

iphone ×1