How to get [UIImage imageWithContentsOfFile:] and High Res Images working(如何让 [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:] 和高分辨率图像工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 [UIImage imageWithContentsOfFile:] 和高分辨率图像工作
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01