如何将图像(不是资源)缩放到 iPhone Retina 在视图中正确显示?
我有一个 UIImage,来自任一设备的相机或从 URL 下载。假设分辨率为 800x600。
我想在 UIImageView 中显示 200x150 的缩放图像,并且我有正确的图像缩放代码。
因此,我只是将 UIImage 缩放到 UIImageView 的frame.size(同样,200x150)。在非视网膜显示屏上,它看起来不错,但在视网膜显示屏上,它看起来很糟糕,就像放大了较小的图片一样,因为实际帧(以像素为单位)是 400x300。
问题是 - 当我调整大小时,如果它是视网膜显示屏,我是否应该手动将 frame.size.width
/height
乘以 2,以便将其大小调整为 400x300 ,或者是否有内置功能?
由于 UIImage 不是设备上的资源,因此我没有 @2x
选项。
I have a UIImage, from either device's camera or downloaded from a URL. Say resolution is 800x600.
I want to display a scaled image in a UIImageView which is 200x150, and I have a proper image scaling code.
So, I just scale the UIImage to the UIImageView's frame.size
(again, 200x150). On a non-retina display it looks OK, but on a retina display it looks bad, like a smaller picture was scaled up, because the actual frame in pixels is 400x300.
The question is - should I, manually multiply the frame.size.width
/height
by 2 when it's a retina display when I resize, so it'll be resized to 400x300, or is there a built in feature for that?
Since the UIImage is not a resource on the device, I don't have the @2x
option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在所有情况下,将图像视图的帧大小保持在 200x150。
如果是非视网膜显示屏,请将图像缩放至 200x150。在视网膜显示设备上将其缩放至 400x300。将
UIImageView
的contentMode
设置为UIViewContentModeScaleAspectFit
。Keep the frame size of the image view at 200x150 in all cases.
In case of non-retina display scale the image to 200x150. On retina display devices scale it to 400x300. Set the
contentMode
of theUIImageView
toUIViewContentModeScaleAspectFit
.当你获得800x600的图像时,你不能制作一个缩放到400x300的UIImage并使用@2x扩展名临时保存它,也许保存到Documents文件夹或tmp文件夹,然后保存另一个缩放到200x150的UIImage并保存它在同一目录中没有@2x。
When you get the image in say 800x600, can't you make a UIImage that is scaled to 400x300 and save it temporarily with the @2x extension, maybe to the Documents folder or tmp folder, and then save another UIImage scaled to 200x150 and save it without the @2x in the same directory.