iPad retina images - Why use two different image sizes? - iphone

For iPad Retina (or iPhone Retina as well), why do we need to have two types of image sizes and add a suffix like #2x for the retina version?
Can't we just have one type of retina resolution images and for devices that do not have retina display, let the device handle resizing the image to smaller (non-retina) size?

Resizing takes time and memory. And resizing while retaining sharpness is hard to do. Which algorithm do you use? Bicubic or bilinear? "But this icon looks better when resized with other-algorithm-here!" How is iOS meant to know that the 1px border you drew is still meant to be a 1px border at half the resolution?

Related

Reducing iOS app size - Are <imagename>#2x.png images redundant?

I am trying to reduce the size (30+ MB) of my binary submission, and I sense that images acquire a sizable (>26 MB) part.
I also observed that if I remove retina images (#2x.png), iOS gracefully replaces them with 4-inch retina (-568h#2x.png) versions.
Are the retina images really redundant if I supply -568h#2x.png versions?
P.S.
Not that one image makes much of a difference, but if the answer is a Yes, does this also apply for default.png?
#2x images are for retina devices. They look much crisper and clean on retina devices (e.g. iPad3, iPhone 5) as compared to their non-retina counterpart images. Here are few suggestions to reduce size of your binary.
1) For background images check if they are really needed. If they are simple solid color images you can simply set the backgroundColor of the UIView.
2) Whenever possible use 9 patch (also called 9 scale) images for button or view backgrounds. They are generally 1 px wide images and you can use below method of UIImage to use them
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode
In general image#2x can be used as a stand in for image, but not the other way around (because they wouldn't look good). The side effect of doing this is that more memory will be used and on non-retina devices that could cause a problem. If you aren't supporting non-retina devices then you don't need any images.
Generally speaking you shouldn't have many image-568h#2x images other than the Default and other background images. Most of your content images will be the same size no matter what the screen size is. You do not need differently named images for a button of the same size on multiple different screen sizes.

How to find that my retina device is using 2x image?

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.

Use only retina images in cocos2d

I am using 2 images: image.png and image-hd.png and it works fine for retina and non-retina too.
But what I want to do now is to remove all non-retina images and leave only retina images. I heard that a non-retina device will scale the image down itself. I tried it but it didn't work :( How I do this? What name should I give to the image that it will show picture its actually size on retina and for non-retina will be scaled down?
No, Retina images are not scaled down automatically.
Only using Retina images and using them scaled down on standard resolution display devices is a bad idea.
Non-Retina devices have far less memory than Retina devices, but you're forcing them to load the Retina resolution images. In other words: device has half the memory, but is forced to load images that consume four times as much texture memory as need be.
Non-Retina devices have slower GPU & CPU. But you're forcing them to work on four times the number of pixels. Performance suffers.
You probably need to scale it down manually. I'm not sure if thats the best idea.
But I think you can just scale down the images to 0.5 if in retina device.
About images, its important to remember that each image is taking memory according to the size of the next power 2 dimensions. Which means that 20X20 pic will take the same memory as 32X32, and 130X260 will take 256X512.
So sometimes just handling your image sizes better or using something like Sprite Sheet.

iPhone/iPad retina image usage preferred?

I understand there is a file naming convention for standard images and retina (higher resolution) images. This is achieved by naming the file as <filename>#2.jpg, as an example.
Now I just ran a test on the iPad simulator that seems to suggest that it would be better to just use the higher resolution, period. The test was this: I had one full-screen image and one retina full-screen image. The low-res image simply has a "1" on it. The hi-res image shows "2" on it. Then I had the hi-res image load to fill the entire screen of the iPad simulator.
Result: It seems like the entire retina image was displayed in the screen.
Expected result: I expected the hi-res image to be partly cropped - I assumed the screen was too small to display the entire retina image.
Obvious questions:
Is my test flawed (am I missing something)?
And if this test can be verified, then why should we include 2 sets of images (standard and retina) if we can simply use retina? The only thing I see is that the retina images consume more memory, so it might be too much for devices that don't have retina displays.
Whether or not the retina (#2x) image is used depends ONLY on the scale factor (the amount of pixels per point) of the screen. Both iPad and iPhone have the same behavior.
You never reference the retina images directly. Instead you load them by saying
[UIImage imageNamed:#"myImage"];
If you are on a retina display the retina version of the image (myImage#2x.png) will be chosen for you. In either case the image takes up the same number of points on the screen. Both the retina and non-retina displays have the same number of points.

Image resolution problem in iPhone 4

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.