I'm applying a CIFilter to a portrait image. For some reason, it gets rotated 90 clockwise. How can I fix this? My code is below
var imgOrientation = oImage.imageOrientation
var imgScale = oImage.scale
let originalImage = CIImage(image: oImage)
var filter = CIFilter(name: "CIPhotoEffect"+arr[sender.tag-1000])
filter.setDefaults()
filter.setValue(originalImage, forKey: kCIInputImageKey)
var outputImage = filter.outputImage
var newImage = UIImage(CIImage:outputImage, scale:imgScale, orientation:imgOrientation)
cameraStill.image = newImage
I'm going to guess that the problem is this line:
var newImage = UIImage(CIImage:outputImage, scale:imgScale, orientation:imgOrientation)
That is not how you render a filter into a UIImage. What you want to do is call CIContext(options: nil)
to get a CIContext, and then send that CIContext the message createCGImage:fromRect:
to get a CGImage. Now turn that CGImage into a UIImage, and, as you do so, you can apply your orientation.
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