我正在使用-drawViewHierarchyInRect:afterScreenUpdates:将view绘制到UIImage中,但似乎无论我做什么,结果总是非常低的分辨率,因为图像似乎需要与原始视图相同的大小?
UIView是屏幕的大小(在本例中为375x667),内容比例因子为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];发布于 2015-05-11 02:38:32
这段代码运行得很好。它会截取当前view的屏幕截图,并将其放入新创建的UIImageView中。请检查一下
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];https://stackoverflow.com/questions/30154597
复制相似问题