如何从CIImage创建灰色8位CGImage?

时间:2015-05-01 13:21:55

标签: ios swift core-graphics avcapturesession core-image

我目前正致力于使用前置摄像头拍摄帧的iOS应用程序。我想比较实际帧与前一帧。为了使速度快,我想创建8位灰度CGImage。

我正在使用AVCaptureSession并且我已经实现了委托:

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
    let image = CIImage(CVPixelBuffer: CMSampleBufferGetImageBuffer(sampleBuffer)).imageByApplyingOrientation(5)
    let img = context.createCGImage(image, fromRect: image.extent(), format: kCIFormatBGRA8, colorSpace: CGColorSpaceCreateDeviceGray())
}

但是这让我崩溃了描述这个颜色空间不受支持。您有什么建议我如何快速创建8位灰度CGImage?

1 个答案:

答案 0 :(得分:0)

抱歉,我不知道你问题的答案,但是你知道有一个CIFilter可以做差异混合:

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIDifferenceBlendMode

可能在您的项目中使用。

西蒙