ios - iOS屏幕捕获模糊

标签 ios screen image-capture

我无法获得不模糊的屏幕截图-首先,我尝试了以下操作:

Screen capture for iOS

它并不模糊,但我认为Apple不会让此代码通过-不会进行审查吗?

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

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

这是我直接从开发支持文档中使用的代码(iOS6,我正在缩放它,但是如果scale为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)允许您通过应用比例因子来创建支持高分辨率屏幕的图形位图上下文。

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

您指定的值为0.65

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.65);

因此会发生一些模糊效果

您可以在iOS Drawing Concepts Guide 点对像素中获得有关使用比例因子的完整信息。

关于ios - iOS屏幕捕获模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16849944/

相关文章:

css - 针对不同屏幕尺寸的多种媒体查询

python - 在单独的 .kv (Kivy) 文件中定义的屏幕之间切换

c++ - OpenCV VideoCapture::set() 返回 false 但成功

python ,OpenCV : Capture Images from WebCam

android - 检测图像是否是使用前置摄像头拍摄的

ios - 可点击的 UILabel

ios - Objective C数组计数字符串问题

ios - 文件夹 iOS 模拟器

ios - Swift 从 didSet 调用委托(delegate)

android - 如何获得屏幕的密度?