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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句