如何让 [UIImage imageWithContentsOfFile:] 和高分辨率图像工作 [英] How to get [UIImage imageWithContentsOfFile:] and High Res Images working

查看:14
本文介绍了如何让 [UIImage imageWithContentsOfFile:] 和高分辨率图像工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如许多人抱怨的那样,在用于 Retina 显示器的 Apple SDK 中似乎存在一个错误,并且 imageWithContentsOfFile 实际上不会自动加载 2x 图像.

As many people are complaining it seems that in the Apple SDK for the Retina Display there's a bug and imageWithContentsOfFile actually does not automatically load the 2x images.

我偶然发现了一篇不错的帖子,如何制作一个检测 UIScreen 比例因子并正确加载低分辨率或高分辨率图像的函数(http://atastypixel.com/blog/uiimage-resolution-independence-and-the-iphone-4s-retina-display/ ),但是该解决方案加载了 2x 图像,并且仍然将图像的比例因子设置为 1.0,这导致 2x 图像缩放了 2 倍(因此,比它看起来要大 4 倍)

I've stumbled into a nice post how to make a function which detects UIScreen scale factor and properly loads low or high res images ( http://atastypixel.com/blog/uiimage-resolution-independence-and-the-iphone-4s-retina-display/ ), but the solution loads a 2x image and still has the scale factor of the image set to 1.0 and this results to a 2x images scaled 2 times (so, 4 times bigger than what it has to look like)

imageNamed 似乎可以准确加载低分辨率和高分辨率图像,但对我来说是没有选择的.

imageNamed seems to accurately load low and high res images, but is no option for me.

是否有人有不使用自动加载 imageNamed 或 imageWithContentsOfFile 来加载低/高分辨率图像的解决方案?(或最终解决如何使 imageWithContentsOfFile 正常工作)

Does anybody have a solution for loading low/high res images not using the automatic loading of imageNamed or imageWithContentsOfFile ? (Or eventually solution how to make imageWithContentsOfFile work correct)

推荐答案

好的,Michael 在这里找到的实际解决方案:http://atastypixel.com/blog/uiimage-resolution-independence-and-the-iphone-4s-retina-display/

Ok, actual solution found by Michael here : http://atastypixel.com/blog/uiimage-resolution-independence-and-the-iphone-4s-retina-display/

他发现 UIImage 有一个方法initWithCGImage",它也接受一个比例因子作为输入(我猜你可以设置自己的比例因子的唯一方法)

He figured out that UIImage has the method "initWithCGImage" which also takes a scale factor as input (I guess the only method where you can set yourself the scale factor)

[UIImage initWithCGImage:scale:orientation:]

这似乎很好用,您可以自定义加载高分辨率图像并将比例因子设置为 2.0

And this seems to work great, you can custom load your high res images and just set that the scale factor is 2.0

imageWithContentsOfFile 的问题在于,由于它目前无法正常工作,因此即使它已修复,我们也无法信任它(因为某些用户的设备上仍会使用较旧的 iOS)

The problem with imageWithContentsOfFile is that since it currently does not work properly, we can't trust it even when it's fixed (because some users will still have an older iOS on their devices)

这篇关于如何让 [UIImage imageWithContentsOfFile:] 和高分辨率图像工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆