iOS屏幕捕获很模糊 [英] iOS Screen Capture is blurry

查看:103
本文介绍了iOS屏幕捕获很模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取不模糊的屏幕截图时遇到了麻烦-首先,我尝试过此操作:

I am having trouble getting a screen shot that is not blurry - first I tried this:

iOS的屏幕截图

并没有模糊,但我认为Apple不会让此代码通过-不会进行审核?

and it was not blurry but I think Apple will not let this code through - won't make the review?

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

so I went with the official solution in the developer docs: similar to this: Capturing Screen

但是当我使用官方"方式时,它创建的图像是模糊的

But when I use the 'official' way, the image it creates is blurry

这是我直接从开发支持文档中使用的代码(iOS6,我正在缩放它,但是如果scale为0则没有区别):

Here is the code I am using straight from the dev support docs (iOS6 and I am scaling it, but there is no difference if scale is 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)允许您通过应用比例因子创建支持高分辨率屏幕的图形位图上下文.

UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale) allows you to create graphic bitmap context which supports high resolution screens by applying scale factor.

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

If you specify a value of 0.0 then the scale factor is set to the scale factor of the device’s main screen. On a standard-resolution screen, the scale factor is typically 1.0. On a high-resolution screen, the scale factor is typically 2.0.

在您的情况下,您将值指定为0.65

In your case you specify the value of 0.65

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65);

所以会产生一些模糊效果

So some blurring effect occurs

您可以在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆