我有一个尺寸为1800 x 2400像素的图像。它以450 x 600的形式显示在UIImageView中。保存UIImage全尺寸,包括UIImageView的变换
我已将UIPinchGestureRecognizer
和UIRotationGestureRecognizer
附加到UIImageView,它允许用户缩放和旋转工作良好的图像。
我现在需要以原始大小(1800 x 2400)导出图像,并进行旋转和变换,我正在努力实现这个功能。
我迄今为止代码:
if let imageView = imageView, let image = imageView.image {
UIGraphicsBeginImageContext(image.size)
let context = UIGraphicsGetCurrentContext();
context?.translateBy(x: 0, y: image.size.height)
context?.scaleBy(x: 1.0, y: -1.0)
context?.rotate(by: -imageView.transform.b)
context?.draw(image.cgImage!, in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
translatedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
}
通过以上,旋转是正确的,但绘制图像偏离中心,我无法弄清楚如何包括变焦。
图形是我在开发中的弱点,我已经在这个几个小时没有成功。
是否可以单独保存图像和转换,然后在想要再次显示时重新应用它们? –