objective-c - 调整大小后的 UIImage 质量较差

标签 objective-c ios uiimage retina-display

我正在尝试创建一个与视网膜和非视网膜显示器兼容的应用程序。我使用高分辨率图像并让操作系统将其缩小以适应非视网膜显示器。

图像名为 [email protected]我用相同的名字加载。这是可行的,并且图像在两种设备类型上以相同的相对尺寸显示。不幸的是,非视网膜显示器上调整大小后的图像质量远非理想。

self.navigationItem.rightBarButtonItem.image = [localAssets imageAtPath:@"content/home/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2152445555484f46526113590f514f46" rel="noreferrer noopener nofollow">[email protected]</a>"];

+ (UIImage*)imageAtPath:(NSString*)path;
{
    NSString* extension = [path pathExtension];
    path = [path stringByDeletingPathExtension];

    NSString* filePath = [[NSBundle mainBundle] pathForResource:[path lastPathComponent] 
                                                         ofType:extension 
                                                    inDirectory:[path stringByDeletingLastPathComponent]];
    UIImage* theImage = [UIImage imageWithContentsOfFile:filePath];

    if(!theImage)
    {
        NSLog(@"Error no file found at %@", [path stringByAppendingPathExtension:extension]);
    }
    return theImage;
}

视网膜:

http://i.imgur.com/gmn1q.png

旧版:

enter image description here

最佳答案

如果您自己调整图像大小,并将它们另存为 xxx.png 和 [email protected] ,然后您可以将它们用作“xxx”,并且当使用 Retina 显示屏时,iOS 将自动使用 @2x 版本。

关于objective-c - 调整大小后的 UIImage 质量较差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11351929/

相关文章:

objective-c - NSMutableDictionary 中的编辑条目失败,错误为 : "unrecognized selector sent to instance"

Objective C 中的 C++ 数组给出 EXC_BAD_ACCESS

ios - iPad Mini 未获取 UIImage 值

javascript - 创建自定义事件,如 ionicPlatform.ready() 或 document.ready()

objective-c - 如何让插件导入 UTI 类型

ios - CALayer 扁平子层

ios - iPhone 上的文件夹和图像在哪里?[swift]

ios - 在 iOS 中处理大图像

image - 如何将普通 UIImage 转换为相应的 NES 调色板颜色?

objective-c - Cocoa 中 AuthorizationExecuteWithPriveleges 的非常奇怪的问题