Chr*_*oph 3 uikit image-rendering swift ios10
UIGraphicsImageRenderer是在 iOS 10 中新引入的。我想知道是否有可能旋转UIImage它(任何自定义角度)。我知道还有就是经典的方式用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
Run Code Online (Sandbox Code Playgroud)