【问题标题】:CMSampleBufferRef to bitmap?CMSampleBufferRef 到位图?
【发布时间】:2013-10-14 00:53:21
【问题描述】:

我正在使用 Apple 网站(Xcode 项目)中的 AVScreenShack 示例,该示例捕获桌面并在准实时的窗口中显示捕获。

我对项目做了一点修改,插入了这行代码:

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

我的问题是:如何将 CMSampleBufferRef 实例转换为 CGImageRef ?

谢谢。

【问题讨论】:

    标签: objective-c xcode macos avfoundation


    【解决方案1】:

    以下是如何从 CMSampleBufferRef 创建 UIImage。在AVCaptureStillImageOutput 上回复captureStillImageAsynchronouslyFromConnection:completionHandler: 时,这对我有用。

    // 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 数据。

    更新:要完全回答您的问题,您可以从我的代码中调用img 上的CGImage 以实际获得CGImageRef

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 2012-03-10
      • 2016-04-30
      • 2013-02-11
      • 1970-01-01
      相关资源
      最近更新 更多