首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS屏幕截图模糊

iOS屏幕截图模糊
EN

Stack Overflow用户
提问于 2013-05-31 04:49:35
回答 1查看 2.1K关注 0票数 1

我在获得一个不模糊的屏幕截图时遇到了麻烦--首先,我尝试了如下:

iOS屏幕截图

而且它并不模糊,但我认为苹果不会让这段代码通过-不会进行审查吗?

因此,我在开发人员文档中使用了官方解决方案:类似于以下内容:捕捉屏

但是当我使用“官方”的方式时,它所创建的图像是模糊的。

下面是我直接从dev support文档中使用的代码(iOS6和我正在缩放它,但是如果scale为0,则没有区别):

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2013-06-05 17:29:55

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

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

在您的例子中,您指定的值为0.65

代码语言:javascript
复制
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65);

所以会出现一些模糊效应

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16849944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档