[Swift] UIImage image rotation

For example, if a project has two cut images of "like" and "dislike", with image rotation, only one cut image can be imported.

    let dzImg = UIImage(named: "icon_dz")!
    let dcImg = flipImage(dzImg)

    // UIImage图片旋转
    private func flipImage(_ image: UIImage) -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale)
        let context = UIGraphicsGetCurrentContext()!
        context.translateBy(x: image.size.width / 2, y: image.size.height / 2)
        context.rotate(by: CGFloat.pi*2)
        context.translateBy(x: -image.size.width / 2, y: -image.size.height / 2)
        context.draw(image.cgImage!, in: CGRect(origin: .zero, size: image.size))
        let flippedImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return flippedImage
    }

おすすめ

転載: blog.csdn.net/u012881779/article/details/130861839