I have some issues applying filters to an image. The following code works perfect when using CIImage:imageWithContentsOfURL:
NSInteger filterIndex = [(UITapGestu
The problem is that
[UIImage imageNamed:@"test.png"].CIImage
doesn't do what you think it does. It doesn't convert a UIImage into a CIImage, or derive a CIImage from a UIImage; it merely provides a reference to the CIImage that is already the basis of this UIImage. But this UIImage does not have a CIImage basis; it is a bitmap (CGImage), not a filter output (CIImage).
That is why, as you have rightly discovered, you have use a different method, CIImage's initWithCGImage:
, which does perform the conversion. The UIImage (as I just said) does have a CGImage basis, so this works.
In other words, a UIImage is (mostly) just a wrapper. It can be a wrapper for a bitmap (CGImage) or for a filter output (CIImage). And those two methods, CGImage
and CIImage
, are merely ways of obtaining what is wrapped; only one of them will work on any given UIImage, and most of the time it will be CGImage
.