【发布时间】:2016-08-13 20:25:06
【问题描述】:
我想将带有透视变换的 UIView 转换为 UIImage,但我得到了没有变换的图像。如何保持转型?
我正在使用以下代码为 UIView 进行透视变换:
var rotationAndPerspectiveTransform = CATransform3DIdentity
rotationAndPerspectiveTransform.m34 = 1.0 / -500
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0 * CGFloat(M_PI) / 180.0, 1.0, 0.0, 0.0)
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0 * CGFloat(M_PI) / 180.0, 0.0, 1.0, 0.0)
self.photoImageView.layer.transform = rotationAndPerspectiveTransform
然后将具有透视变换的 UIView 转换为 UIImage:
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0)
view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
结果我得到了正确的图像,但没有透视
【问题讨论】:
-
@LeoDabus 同样的结果
-
@LeoDabus UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0.0) photoImageView.layer.presentationLayer()!.renderInContext(UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext UIGraphicsEndImageContext() 没有帮助
标签: ios swift uiview uiimage core-animation