【发布时间】:2017-05-19 22:37:05
【问题描述】:
我正在通过以下代码在图像层上应用 3D 变换。
UIImageView *view = (UIImageView *)[recognizer view];
CGPoint translation = [recognizer translationInView:self.view];
CGPoint newCenter = view.center;
newCenter.x += translation.x;
newCenter.y += translation.y;
view.center = newCenter;
[recognizer setTranslation:CGPointZero inView:self.view];
以下是将点转换为变换的位置。
[self.view transformToFitQuadTopLeft:self.topLeftControl.center
topRight:self.topRightControl.center
bottomLeft:self.bottomLeftControl.center
bottomRight:self.bottomRightControl.center];
为了将转换图像保存到 UIImage,我使用renderInContext 使用以下代码。
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
第二次使用drawViewHierarchyInRect
UIGraphicsBeginImageContextWithOptions(self.toothImageView_1.bounds.size, NO, 0);
BOOL ok = [self.toothImageView_1 drawViewHierarchyInRect:self.toothImageView_1.bounds afterScreenUpdates:YES];
UIImage *img = nil;
if( ok )
{
image = UIGraphicsGetImageFromCurrentImageContext();
}
self.imageView.image = image;
UIGraphicsEndImageContext();
我得到的是原始的带框方形图像,而不是转换后的图像。我实际上需要将 3d 转换图像保存在文档目录中。
提前致谢。欢迎任何建议和答案。
【问题讨论】:
标签: ios objective-c uiimageview transform layer