Search code examples
ioscameracore-imagecifilter

CIFilter filterWithCVPixelBuffer returning nil in iOS


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.


Solution

  • 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).