如何强制-drawViewHierarchyInRect:afterScreenUpdates:以@ 2x分辨率拍摄快照?

ope*_*rog 2 iphone core-graphics ipad ios ios7

-drawViewHierarchyInRect:afterScreenUpdates:是iOS 7中快速查看视图层次结构的快照方式.

它需要快照,但分辨率为@ 1x.iPhone 5S上的快照看起来像素化且模糊.我没有转换创建快照的视图.

我不想模糊它,并希望在屏幕上看到良好​​的质量.我是如何捕获它的:

UIGraphicsBeginImageContext(self.bounds.size);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, self.contentScaleFactor);
Run Code Online (Sandbox Code Playgroud)

仍然呈现低@ 1x质量.

有没有其他方法来配置图像上下文,所以它是@ 2x分辨率?

gra*_*ver 13

正确的是:

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f);
Run Code Online (Sandbox Code Playgroud)

  • 参见[UIGraphicsBeginImageContextWithOptions`的文档](https://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIGraphicsBeginImageContextWithOptions):"要应用于位图的比例因子.如果指定值0.0,则比例因子将设置为设备主屏幕的比例因子." (4认同)