【问题标题】:Captured UIView image has distorted colors (iPhone SDK)捕获的 UIView 图像颜色失真(iPhone SDK)
【发布时间】:2010-12-26 12:59:47
【问题描述】:

我正在使用 UIGraphicsGetImageFromCurrentImageContext() 函数将屏幕内容捕获到 UIImage 对象中(之前渲染到 Image 上下文中)。这对模拟器和真实设备都很有效,但是在后者中,生成的图像有几个像素颜色失真,如下所示:

http://img300.imageshack.us/img300/2788/screencap.png

请注意顶部导航栏、搜索栏两侧和按钮右侧的几个紫红色像素。左下角按钮的右侧也有这样的像素。

我用来将屏幕视图捕获到 UIImage 对象中的代码非常简单:

UIGraphicsBeginImageContext(self.view.window.frame.size);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

需要注意的是,所有被扭曲的图形都属于自定义 PNG 文件,用于绘制搜索字段背景以及按钮背景。

有谁知道可能导致这种奇怪的颜色失真的原因是什么?

最好的问候,

【问题讨论】:

    标签: iphone uiview screen-capture


    【解决方案1】:

    刚刚检查了我自己的代码,它和你做的事情是一样的。你的几乎和我的一样,只是我要求视图的图层而不是窗口的图层进行渲染,即:

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    

    我不知道为什么会有所作为,但值得一试。

    【讨论】:

      【解决方案2】:

      使用刚刚批准的私有函数UIGetScreenImage()解决了。

      更多信息,请查看http://www.tuaw.com/2009/12/15/apple-relents-and-is-now-allowing-uigetscreenimage-for-app-st/https://devforums.apple.com/message/149553

      问候,

      【讨论】:

        【解决方案3】:

        本文解释了图像损坏(由部分透明像素引起)的问题,并提供了一种解决方法来证实 Chris 的评论:

        http://www.kaoma.net/iphone/?p=9

        【讨论】:

          【解决方案4】:

          当您只想捕获视图时,UIGetScreenImage() 非常烦人。 我发现了一个不错的技巧,只需使用 Preview.app 将所有 PNG 图像重新保存为 TIFF 格式 :)

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2011-03-16
            • 1970-01-01
            • 2018-12-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2022-11-11
            相关资源
            最近更新 更多