Mrw*_*lfy 2 iphone xcode render uiview
我有一个包含图形的视图(称为outPutView),如uIImageViews和标签.我需要渲染outPutView的图像及其子视图.我正在使用renderInContext:UIGraphicsGetCurrentContext()来做到这一点.工作正常,但我需要缩放视图.我在outPutView上使用转换.这会成功缩放视图及其子视图,但转换不会呈现.虽然视图在屏幕上缩放.最终渲染以原始大小显示视图,而渲染上下文为目标大小(此处为@ 2x iPhone视图大小).
谢谢阅读!!
[outPutView setTransform:CGAffineTransformMake(2, 0, 0, 2, 0, 0)];
CGSize renderSize = CGSizeMake(self.view.bounds.size.width*2, self.view.bounds.size.height*2);
UIGraphicsBeginImageContext(renderSize);
[[outPutView layer] renderInContext:UIGraphicsGetCurrentContext()];
renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
我刚刚完成了这项工作,尽管方向相反(缩小).以下是相关代码的摘要:
// destination size is half of self (self is a UIView)
float rescale = 0.5;
CGSize resize = CGSizeMake(self.width * rescale, self.height * rescale);
// make the destination context
UIGraphicsBeginImageContextWithOptions(resize, YES, 0);
// apply the scale to dest context
CGContextScaleCTM(UIGraphicsGetCurrentContext(), rescale, rescale);
// render self into dest context
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
// grab the resulting UIImage
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
要向上扩展而不是向下扩展,应该没问题rescale = 2.
| 归档时间: |
|
| 查看次数: |
2204 次 |
| 最近记录: |