【发布时间】:2015-07-21 04:27:33
【问题描述】:
我正在使用-drawViewHierarchyInRect:afterScreenUpdates: 将view 绘制成UIImage,但似乎无论我做什么结果总是分辨率很低,因为图像似乎需要相同大小作为原始视图?
UIView 是屏幕大小(在本例中为 375 x 667),内容比例因子为 2.0f。
但是当我使用-drawViewHierarchyInRect:afterScreenUpdates: 将view 绘制到image 上时,它的大小(可怕地)调整为这个分辨率,即使内容的分辨率要高得多。
我使用UIGraphicsBeginImageContextWithOptions 以0.0 的比例创建image,所以我认为它应该画得很好,但不行。如何在不丢失细节的情况下绘制视图层次结构?
编辑: 这是一些示例代码(来自下面的答案,给出了相同的结果)。在尝试绘制包含高分辨率图像的 UIView 层次结构时,它给了我非常缩小的结果:
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);
[self.view drawViewHierarchyInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.frame = self.view.bounds;
[self.view addSubview:imgView];
[self.view bringSubviewToFront:imgView];
【问题讨论】:
-
您可以将代码粘贴到您的问题中吗?
标签: ios objective-c uiview