iOS屏幕捕捉是模糊的

我很难得到一个不模糊的屏幕截图 – 首先我试过这个:

iOS屏幕截图

这不是模糊的,但我认为苹果不会让这个代码通过 – 不会做审查?

所以我使用了开发人员文档中的官方解决scheme:类似于: 捕获屏幕

但是,当我使用“官方”的方式,它创造的形象是模糊的

这里是我直接从开发支持文档(iOS6和我缩放,但没有区别,如果规模为0)的代码:

CGSize imageSize = [[UIScreen mainScreen] bounds].size; if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65); else UIGraphicsBeginImageContext(imageSize); CGContextRef context = UIGraphicsGetCurrentContext(); // Iterate over every window from back to front for (UIWindow *window in [[UIApplication sharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { // -renderInContext: renders in the coordinate space of the layer, // so we must first apply the layer's geometry to the graphics context CGContextSaveGState(context); // Center the context around the window's anchor point CGContextTranslateCTM(context, [window center].x, [window center].y); // Apply the window's transform about the anchor point CGContextConcatCTM(context, [window transform]); // Offset by the portion of the bounds left of and above the anchor point CGContextTranslateCTM(context, -[window bounds].size.width * [[window layer] anchorPoint].x, -[window bounds].size.height * [[window layer] anchorPoint].y); // Render the layer hierarchy to the current context [[window layer] renderInContext:context]; // Restore the context CGContextRestoreGState(context); } } // Retrieve the screenshot image UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; 

UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale)允许您通过应用比例因子来创build支持高分辨率屏幕的graphics位图上下文。

如果您指定的值为0.0,则缩放系数将设置为设备主屏幕的缩放系数。 在标准分辨率屏幕上,比例因子通常为1.0。 在高分辨率屏幕上,比例因子通常为2.0。

在你的情况下,你指定0.65的值

 UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65); 

所以会出现一些模糊的效果


您可以在iOS绘图概念指南 与像素中获得有关使用比例因子的完整信息