gpt4 book ai didi

swift - 使用 UIGraphicsImageRenderer 旋转图像?

转载 作者:搜寻专家 更新时间:2023-11-01 06:18:29 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com