I have implemented a CIFilter to profileImages in my iOS app. I have added orientation to prevent pixelation but I am suffering from the aspect ratio "ScaleAspectFill" not being applied to the images. The same images in colour have the perfect aspect ratio...i.e. when I just have:
self.p1ProfilePic.image = p1Img
What am I missing here? CGRect?
let originalImageP1 = CIImage(image: p1Img!)
let filter = CIFilter(name: "CIPhotoEffectTonal")
filter!.setDefaults()
filter!.setValue(originalImageP1, forKey: kCIInputImageKey)
let outputImage = filter!.outputImage
self.p1ProfilePic.image = UIImage(CIImage: outputImage!, scale: UIScreen.mainScreen().scale, orientation: .Up)
Creating a UIImage
from a CIImage
with your technique creates images that don't respect contentMode
. Try this instead:
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(filter.outputImage!,
fromRect: filter.outputImage!.extent)
self.p1ProfilePic.image = UIImage(CGImage: cgImage)
Cheers!
Simon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With