我使用-drawViewHierarchyInRect:afterScreenUpdates:
繪製view
到UIImage
,但似乎不管我做了什麼,結果始終是一個非常低的分辨率,因爲圖像似乎需要與原始視圖大小相同?UIView drawViewHierarchyInRect給出像素化結果?
UIView
是屏幕的大小(本例中爲375 x 667),內容比例因子爲2.0f。
但是,當我使用-drawViewHierarchyInRect:afterScreenUpdates:
將view
繪製到image
上時,即使內容的分辨率高得多,也會調整(可怕)該分辨率。
我使用的是UIGraphicsBeginImageContextWithOptions
,其比例爲0.0來創建image
,所以我認爲它應該很好地繪製,但沒有去。你如何繪製視圖層次結構而不會丟失細節?
編輯: 下面是一些示例代碼(來自下面的答案,它給出了相同的結果)。
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];
你可以粘貼你的代碼在你的問題? – Tobias