gpt4 book ai didi

ios - 如何在 iPhone 上将 @1x iPad 图像加载为 @2x 图像?

转载 作者:可可西里 更新时间:2023-11-01 05:44:43 26 4
gpt4 key购买 nike

我正在开发一款包含数百张背景图片的通用应用程序。为了节省磁盘空间并防止进一步复制和磁盘垃圾邮件,我想将非视网膜@1x iPad 图像重新用作视网膜@2x iPhone 图像。

例子:

background125_iPad@2x.png
background125_iPad.png

iPhone 4 和 5 的宽高比不同,因此我将缩放 1024x768 图像以适应。

但问题是,如果我在 iPhone 5 上使用它:

UIImage *img = [UIImage imageNamed:@"background125_iPad.png"];

然后 iOS 会尝试比我更聪明并选择巨大的内存怪物@"background125_iPad@2x.png"版本。

有没有一种说法:“iOS,看。我比你聪明。我希望你加载这个文件。我的意思是这个文件。这个。把它当作@2x 版本比例因子为 2。”这样它就真的加载了请求的“background125_iPad.png”文件,但是 UIImageView 就像它有 512 x 384 点(= 1024x768 像素)一样?

我假设 UIImage imageNamed 不是正确的选择?

最佳答案

我认为您无法关闭该功能。

但你总是可以这样做:

UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background125_iPad" ofType:@"png"]];
UIImage *scaledImage = [UIImage imageWithCGImage:[img CGImage]
scale:[[UIScreen mainScreen] scale]
orientation:img.imageOrientation];

这不会自动添加设备特定的后缀。我建议将其封装到 UIImage 类别中以便更简单地使用:)

关于ios - 如何在 iPhone 上将 @1x iPad 图像加载为 @2x 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20219090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com