【问题标题】:Cropping a UIImage makes it rotate 90º anti-clockwise upon saving裁剪 UIImage 使其在保存时逆时针旋转 90º
【发布时间】:2018-06-08 12:06:28
【问题描述】:

我正在制作一个带有AVFoundation 的全屏摄像头的应用。我直接保存 UIImage 而不压缩它。它给了我想要的输出,也就是说,它保存了带有拍摄方向的图像。但是当我尝试将其裁剪为矩形(CGRect)时,它像以前一样保存了图像。这是我所做的:

@objc func saveTapped() {
        myIndicator.isHidden = false
        guard let imageToSave = imageToShow else { return }
        let crop = CGRect(x: 0, y: 0, width: 1440.0, height: 2560.0)
        let croppedCGImage = imageToSave.cgImage?.cropping(to: crop)
        let croppedUIImage = UIImage(cgImage: croppedCGImage!)
        UIImageWriteToSavedPhotosAlbum(croppedUIImage, nil, nil, nil)
        myIndicator.stopAnimating()
    }

我不知道如何以我想要的方向保存它们。请帮忙!

【问题讨论】:

    标签: ios uiimage swift4 cgimage


    【解决方案1】:

    从下面的行更改

    let croppedUIImage = UIImage(cgImage: croppedCGImage)
    

    let croppedUIImage = UIImage(cgImage: croppedCGImage, scale: imageToSave.scale, orientation: imageToSave.imageOrientation)
    

    【讨论】:

      猜你喜欢
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      相关资源
      最近更新 更多