I am trying to use CGImageCreateWithMask to mask an image (CGImageRef). The result is another CGImageRef which I store in a local variable. When I perform CGImageCreateWithMask on the result of the first pass (CGImageRef local variable), I get nil.
CGImageRef maskedImage1 = CGImageCreateWithMask(image, mask);
CGImageRef maskedImage2 = CGImageCreateWithMask(maskedImage, mask);
UIImage * finalImage = [UIImage imageWithCGImage:maskedImage2];
maskedImage1 seems to be correct (I tried displaying it as well). maskedImage2 is nil.
The CGImageRef that CGImageCreateWithMask returns still has alpha component and it can be treated like any other CGImageRef, right? Am I missing something?