Image rotated after CIFilter

I am applying CIFilter to a portrait image. For some reason, it spins 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

      

+3


source to share


1 answer


I'm going to assume that the problem is on this line:

var newImage = UIImage(CIImage:outputImage, scale:imgScale, orientation:imgOrientation)

      



This is not how you represent a filter in UIImage. What you want to do is call CIContext(options: nil)

to get the CIContext and then send the CIContext message createCGImage:fromRect:

to get the CGImage. Now turn this CGImage into a UIImage and the way you do this you can apply your orientation.

+7


source







All Articles