我正在使用
但是,当我使用
我正在使用比例为0.0的
编辑: 这是一些示例代码(来自下面的答案,给出了相同的结果)。尝试绘制包含高分辨率图像的UIView层次结构时,它给我带来了可怕的缩小结果:
-drawViewHierarchyInRect:afterScreenUpdates:
将view
绘制到UIImage
中,但无论我做什么,结果总是非常低的分辨率,因为图像似乎需要与原始视图大小相同?
UIView
的大小为屏幕大小(在此情况下为375 x 667),内容比例因子为2.0f。但是,当我使用
-drawViewHierarchyInRect:afterScreenUpdates:
将view
绘制到image
上时,它会被调整大小(非常糟糕),即使内容分辨率更高。我正在使用比例为0.0的
UIGraphicsBeginImageContextWithOptions
创建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];