My app will download a image and display it into a UIImageView.
The image is quite large, say 600 * 600 and the UIImageView's size is 100 * 100.
So when the image is displayed, I set the UIImageView to scale it to fit.
My question is
For iPhone 3Gs, I understand the image is scaled to 100 * 100 directly and displayed in UIImageView.
But what about iPhone 4? When I do imageView.image = image, will iOS automatically scale the image to 200 * 200 first and then display it in 100 * 100 imageView?
I mean should I do anything extra to make sure that the Retina display is adapted?
Thanks
In this case, no, you needn't do anything particular. If your UIImageView is well configured (scale to fit, as it seems you've done), an iPhone4 will display your image scaled at 200x200 pixels in a 100x100 points UIImageView. No need either to download a different "whatever#2x.png" image.
You don't have to do anything specific here. Your image will be scaled appropriately by UIKit and in fact it's the UIImageView which will be affected by the Retina display, not your image. You specify a size of 100 x 100 which on non-Retina displays will hold true, but on Retina displays under the surface the physical size will actually be 200 x 200 because it'll take into account the scaleFactor.
Either way, the UIImageView will scale the image accordingly.
I have an experience that it works opposite way..so scale it for retina and iphone 3G or 3GS will display it correctly.
Related
I know that 2x images are for retina display.
But i want to know that how can we identify that my device is using 1x image or 2x image?
and one more thing
I have one image name stackOverflow.png of size 50x50 and its 2x with name stackOverflow#2x.png of size 100x98.
My question is that device will select retina image with name or size???
To check which one has been loaded, you can use this code:
UIImage *image = [UIImage imageNamed:#"image"];
NSLog(#"scale: %f", image.scale); //this will be 2.0 for retina image
Or just simply use two different images, as #MidhunMP suggested in comments.
It's usually not hard to tell just by looking at them-- especially in the iOS simulator. Set the simulator to retina mode and take a look. Non-retina images will be visibly blurry compared to retina images.
As for the image size, if your 2x image is not actually 2x the size of the original image, you are doing it wrong. Fix one image or the other, or both. Retina images are selected by name. If the size is wrong, the image will be stretched to fit. That will ruin the high-resolution retina effect you're trying to get with a 2x image.
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.
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.
I am showing a high resolution image in iphone 4 and i set the image view frame size as below :
imageFrameNormal.size.width = 470;
imageFrameNormal.size.height = 625;
but it showing full screen instead of this size. so plz can any one suggest how i show image in right size.
i am trying to check it in simulator.
Thx
You have to use the same sizes on retina and normal displays. For example, you have image view with size 100x100. On retina device you should use the same size 100x100 (no changes in your code). However you'd better use high-res image (2x size). For this you need to name it properly:
image.png - normal size image
image#2x.png - 2x size image.
When you call
UIImage* img = [UIImage imageNamed: #"image.png"];
image.png would be used on normal display and image#2x.png on retina (iOS does it automatically).
The retina display's coordinate system is not in pixels, but in "points". The iPhone display, whether retina or legacy will always be 320x480 points. When interacting with any parameters such as the frame, size, origin, etc., you will need to remember to use points instead of pixels. The OS will handle the "conversion" between points and pixels for you.
For a much more detailed explanation, see Points vs. Pixels in the Drawing and Printing Guide for iOS.
I am having a problem in iphone 4. The images used in iPhone less than 4 are fine but when I upgraded to iphone 4 the images looks distorted.
Here is the link.
The image size I have used is 320 x 480.
http://img822.imageshack.us/img822/8431/download22.png
Thanks.
The fact is that the resolution of iPhone4 is 960x640 instead that 480x320 so the image is scaled with linear (or bilinear, not sure) filtering.. the result is what you get: a blurry image.
Just redo the image with the proper resolution to solve the problem, you mainly notice these kinds of artifacts because you have rasterized text on an image..
You obtain this effect whenever you resize an image to fit a wider area of pixels: the missing pixels must be filled somehow and filtering comes into play. So you will have to consider also that part of the screen is used by the top bar to have an exact sized picture.
Create a #2x suffix to each of your png that you use.
example:
Icon.png
Icon#2x.png
The runtime environment will choose the double-resolution on retina display devices.
It looks like your original image is 480x320, but you aren't accounting for the fact that the status bar is compressing your image slightly (or perhaps it does on the iPhone4 but on the older iPhones it is cropping instead).
I'd check the image view settings for that background image.
I would like to stop a UIImageView from upscaling as it looks terrible. Unfortunately, I cannot control the UIImage content it is holding, so need to force it not to attempt the upscale on an iPhone 4 retina display.
What's the best advice here?
Set its frame manually, I think.
Unless you are always using 2x images (for retina display), then you can multiply the width/height with 0.5.