UIGraphicsImageRenderer
是在 iOS 10 中新引入的。我想知道是否有可能用它旋转 UIImage
(任何自定义角度)。我知道有 classic way使用 CGContextRotateCTM
。
最佳答案
您可以设置 UIGraphicsImageRenderer 来创建图像并调用 UIGraphicsGetCurrentContext() 并旋转上下文
let renderer = UIGraphicsImageRenderer(size:sizeOfImage)
let image = renderer.image(actions: { _ in
let context = UIGraphicsGetCurrentContext()
context?.translateBy(x: orgin.x, y: orgin.y)
context?.rotate(by: angle)
context?.draw(image.cgImage!, in: CGRect(origin: CGPoint(x: -orgin.x,y: -orgin.y), size: size))
}
return image
关于swift - 使用 UIGraphicsImageRenderer 旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39089148/