I'm trying to apply a Core Image filter to an UIImage. For that I want to get the CIImage format of the UIImage.
I'm trying to obtain the CIImage of the UIImage as shown below.
if let inputImage = self.orginalImageView.image{
if let ciImage = CIImage(image: inputImage){
print(ciImage)
print(self.orginalImageView.image?.ciImage)
}
}
}
This method works. But one thing I noticed is that there is already a ciImage property and it inside UIImage and it is always nil.
According to documentation
ciImage The underlying Core Image data.
var ciImage: CIImage? { get }
Discussion If the UIImage object was initialized using a CGImage, the value of the property is nil.
Does accessing image property of UIImage comes from CGImage so that the ciImage porperty is nil?
A UIImage
is a wrapper that can be backed by different types of images. The ciImage
property is only set when the UIImage
was created from a CIImage
using CIImage(image:)
. In most cases, however, a UIImage
is backed by a CGImage
.
If you want to create a CIImage
from a UIImage
, you should always use the CIImage(image:)
initializer and never rely on the ciImage
property.