为什么图像在 let cimg = CIImage(image: self.img) 后旋转 90 度

why the image rotate 90 degrees after let cimg = CIImage(image: self.img)

我正在使用 apple core image 处理图像,当我将 UIImage 转换为 CIImage 时,图像似乎旋转了 90 度。主要代码如下,

 struct PhotoDetailView: View {
    @Binding var img:UIImage
    var body: some View {
        
        print(self.img.size)
        let cimg = CIImage(image: self.img)
        print(cimg?.extent.size)
       
      let context = CIContext()
       
      let filter = CIFilter(name: "CIPhotoEffectMono")!
    
        filter.setValue(cimg, forKey: kCIInputImageKey)
      let result = filter.outputImage!
        print(result.extent.size)

打印输出: (3024.0, 4032.0) 可选((4032.0,3024.0)) (4032.0, 3024.0)

你应该保留图像的方向信息

 let orientation = self.img.imageOrientation
 let cimg = CIImage(image: self.img)
 let context = CIContext()
 ...
 let img2 = UIImage(cgImage: cgImage!, scale: 1.0, orientation: orientation)