2013-10-14 31 views
1

我玩弄從蘋果公司的網站(Xcode項目)的AVScreenShack例如捕捉桌面,並顯示在準實時的窗口捕獲。CMSampleBuffer參考位圖?

我已經修改了項目一點點,插入這行代碼:

-(void)captureOutput:(AVCaptureOutput*) captureOutput didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer fromConnection:(AVCaptureConnection*) connection 
{ 
... 
} 

我的問題是:如何將CMSampleBufferRef實例轉換CGImageRef?

謝謝。

回答

2

這裏是你如何創建從CMSampleBufferRef一個UIImage。這對我captureStillImageAsynchronouslyFromConnection:completionHandler: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數據。

更新:要完全回答您的問題,您可以撥打電話CGImageimg從我的代碼實際得到CGImageRef