Image rotating after CIFilter

后端 未结 2 1363
生来不讨喜
生来不讨喜 2021-01-13 08:31

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         


        
2条回答
  •  我在风中等你
    2021-01-13 09:13

    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.

提交回复
热议问题