How to scale images (not resources) to iPhone Retina display correctly in a view?
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 quest开发者_高级运维ion 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.
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 the UIImageView
to UIViewContentModeScaleAspectFit
.
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.
精彩评论