我正在玩苹果网站的AVScreenShack示例(Xcode项目),它捕捉桌面,并在窗口中以准实时方式显示捕获。
我修改了这个项目,并插入了这一行代码:
-(void)captureOutput:(AVCaptureOutput*) captureOutput didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer fromConnection:(AVCaptureConnection*) connection
{
...
}我的问题是:如何将CMSampleBufferRef实例转换为CGImageRef?
谢谢。
发布于 2013-10-14 04:22:31
下面是如何从一个UIImage创建一个CMSampleBufferRef。在响应captureStillImageAsynchronouslyFromConnection:completionHandler: on AVCaptureStillImageOutput时,这对我起了作用。
// CMSampleBufferRef imageDataSampleBuffer;
CMBlockBufferRef buff = CMSampleBufferGetDataBuffer(imageDataSampleBuffer);
size_t len = CMBlockBufferGetDataLength(buff);
char * data = NULL;
CMBlockBufferGetDataPointer(buff, 0, NULL, &len, &data);
NSData * d = [[NSData alloc] initWithBytes:data length:len];
UIImage * img = [[UIImage alloc] initWithData:d];看起来来自CMBlockBufferGetDataPointer的数据是JPEG数据。
更新:要完全回答您的问题,可以从我的代码中调用CGImage on img来获得一个CGImageRef。
https://stackoverflow.com/questions/19352026
复制相似问题