【问题标题】:Blurry UIImages模糊的 UIImages
【发布时间】:2012-01-13 18:51:00
【问题描述】:

我在尝试显示小 (16x16) UIImage 时遇到问题,它们看起来有点模糊。 这些 UIImage 是我从不同网站下载的图标,我将它们与其他应用程序中的一些图像进行了比较,它们更加模糊。

我将它们显示在自定义 UITableViewCell 上,如下所示:

NSData *favicon = [NSData dataWithContentsOfURL:[NSURL URLWithString:[subscription faviconURL]]];

    if([favicon length] > 0){
        UIImage *img = [[UIImage alloc] initWithData:favicon];

        CGSize size;
        size.height = 16;
        size.width = 16;
        UIGraphicsBeginImageContext(size);
        [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        cell.mainPicture.image = scaledImage;
    }

我的自定义 UITableViewCell 或我下载图像的方式有什么问题吗?

谢谢。

[EDIT 1]:顺便说一下,.ico 和 .png 看起来一样。 [编辑 2]:我正在使用 iPad 2,所以没有 Retina 显示屏。

【问题讨论】:

    标签: objective-c uiimage blurry


    【解决方案1】:

    当您向用户显示结果 UIImage 时,您是否在像素边界上对齐视图?

    theImage.frame = CGRectIntegral(theImage.frame);
    

    如果您的视图使用非整数值定位或调整大小,您的大部分图形和文本会显得模糊。如果您在模拟器中运行您的应用,您可以打开“颜色未对齐的图像”以突出显示偏移量不佳的元素。

    【讨论】:

    • 感谢 kubi 的帖子和stackoverflow.com/questions/2034016/… 中的 n8gray 帖子,我发现了问题 我的 UIImageView 是 35px 宽,我试图将 16px 宽的图像居中,这会在图像的回声侧留下 9.5px ...谢谢大家
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多