I am trying to create a CIFilter using filterWithCVPixelBuffer and it is returning nil. This is what I'm trying to do:
CFDictionaryRef options = CMCopyDictionaryOfAttachments(nil, photo.pixelBuffer, kCMAttachmentMode_ShouldPropagate);
CIFilter * ciFilter = [CIFilter filterWithCVPixelBuffer:photo.pixelBuffer properties:(__bridge NSDictionary*)options options:nil];
photo is an instance of AVCapturePhoto given to the delegate. I am using iOS 12 and running the code on iPhone7.
The problem was in the properties NSDictionary. I should have simply passed photo.metadata. So the function call would look like:
CIFilter * ciFilter = [CIFilter filterWithCVPixelBuffer:photo.pixelBuffer properties:photo.metedata options:nil];
Of course, you can pass an NSDictionary
containing the desired CIRAWFilterOption(s)
.
I think I found the answer in the documentation in the header file:
Returns a CIFilter that will in turn return a properly processed CIImage as "outputImage".
Note that when using this initializer, you should pass in a CVPixelBufferRef with one of the following Raw pixel format types kCVPixelFormatType_14Bayer_GRBG, kCVPixelFormatType_14Bayer_RGGB, kCVPixelFormatType_14Bayer_BGGR, kCVPixelFormatType_14Bayer_GBRG as well as the root properties attachment from the CMSampleBufferRef .
So I guess this method should be used when you have a CMSampleBuffer
and is not feasible when coming from a AVCapturePhoto
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.