我一直在努力从转换的UIImageViews生成高分辨率图像。 我有一个画布视图,其中包含由用户手指转换的几个视图。 所以我尝试根据它们的变换渲染这些视图的图像。 这是我用于视图的代码捕捉。
CGSize canvasSize = CGSizeMake(HIRES_WIDTH, HIRES_WIDTH);
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(HIRES_WIDTH / canvasView.frame.size.width, HIRES_WIDTH / canvasView.frame.size.width);
UIGraphicsBeginImageContext(canvasSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGPoint center = imageView.center;
CGSize size = imageView.bounds.size;
CGRect frame = CGRectMake(center.x - size.width, center.y - size.height, size.width, size.height);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, size.width / 2, size.height / 2);
transform = CGAffineTransformConcat(transform, photoImageView.transform);
transform = CGAffineTransformConcat(transform, scaleTransform);
CGContextConcatCTM(context, transform);
[photoImageView.image drawInRect:frame];
CGContextRestoreGState(context);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
但是我在最终图像上得到了偏移差异。 任何建议将不胜感激。
感谢。
答案 0 :(得分:0)
尝试改变这一点:
CGRect frame = CGRectMake(center.x - size.width, center.y - size.height, size.width, size.height);
对此:
CGRect frame = CGRectMake(center.x - size.width / 2, center.y - size.height / 2, size.width, size.height);