【发布时间】:2017-06-01 10:10:07
【问题描述】:
我有一张全尺寸为 1800 x 2400 像素的图像。它以 450 x 600 的分辨率显示在 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();
}
使用上述方法,旋转是正确的,但图像偏离中心,我不知道如何包括缩放。
图形是我在开发过程中的弱点,我已经在这方面做了好几个小时,但没有成功。
【问题讨论】:
-
是否可以分别保存图像和转换,然后当您想再次显示时重新应用它们?
标签: ios swift core-graphics