Image rotating after CIFilter

后端 未结 2 1360
生来不讨喜
生来不讨喜 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:12

    You can try this :

    let cgImage = self.context.createCGImage(filterOutputImage,
                                             from: cameraImage.extent)!
    
    let orientation: UIImage.Orientation =
          currentCameraType == AVCaptureDevice.Position.front ?
               UIImage.Orientation.leftMirrored:
               UIImage.Orientation.right
    
    let image = UIImage(cgImage: cgImage,
                        scale: 1.0,
                        orientation: orientation)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题