Using image for text in retina and non retina screen - iphone

I'm doing a book in which I display text with images in order to get the exact text layout I want.
The problem is that the text is crispy on non-retina display if I use retina images (image with *2 resolution). For the moment, I've added pages for retina and non-retina display but this means my application is bigger.
Is there a way to use only retina ressources and to have a nice text even on non-retina display ?

No, you can't,:( since the non retina display is having less resolution screen compared to retina display thats why the concept of normal image and #2x image was introduced.
If you use UIImage's imageNamed property with your image it will automatically renders respective images wrt the devices,
ex:- if your image name is background.png and for retina display background#2x.png then once you write
backgroundImgView.image = [UIImage imageNamed:#"background"];
it will automatically assigns normal & #2x image to non-retina & retina display.

Related

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.

Retina graphics

I'm using an image that fills the screen (like a background) to my app. The image is already in retina dimensions, but I scaled it to fit the simulator screen. Because it's already in retina dimensions, do I still need to add a copy of it with the #2x extension?
It's better to use separate images, normal & normal#2x. if you only use single image, small images will be distorted while bigger image will look squeezed.
don't forget the iphone 5 for background images for example.
3 images are required : Background-568h.png Background.png Background#2x.png
if ([UIScreen mainScreen].bounds.size.height > 480.0f) {
// for the iPhone 5
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background-568h.png"]];
} else {
// for iphone 3.5 inch retina /non retina.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
}
the naming notation is required for compiler to detect your retina images.if you write image.png the compiler looks for image#2x.png and then image.png and if it can not find it(for retina displays).
So name all your images xxx#2x.png and provide also xxx.png for non retina devices.
On the other hand i would use exact image sizes for non-strechable images in you app.Resizing means extra time and naturally extra computation.On the other hand fractional image resolutions ends up with blurry images.
For iphone 5 images you should for instance include Iphone5BackgorundIamge#2x.png but call Iphone5BackgorundIamge.png in your code.
Iphone dont have to do with image dimension but it uses image name for checking whether it is to be used as ratina or normal image.You have to keep a normal size image with it's name like "image1.png" for normal display and ratina size image as "image1#2x.png" for ratina display.If your used image is already of ratina display then keep it with #2x format and put one half size image with normal name.

iPad retina images - Why use two different image sizes?

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?

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.

background image size iphone

Normal background image is 320x480 pixels. and for retina is 640x960 pixels.
Now i have to put my background image and i have status bar(20) and navigation bar (44).
So i have to reduce 64(20+44) from 480(normal) or from 960(retina)?
if i reduce 64 from normal then normal image will be 320x416 pixels and retina will be 640x832 pixels.
if i reduce 64 from retina then normal will be 320x448 and retina will be 640x896 .
It is confusing me.. this 64(20+44) i reduce from which image type because other one will be exactly half or double of it.
Reduce from the normal size.
64px = height to remove from normal display.
128px = height to remove from the retina.
Don't forget that in the retina display the status bar and nav bar will also be 2x the height :)
You do everything based upon the 320x480 size, then retina scales everything up. Using images suffixed #2x will allow you to replace the assets (mainly UIImage) for the retina version, this doesnt work for direct resource file references or video/audio files though so just be careful.
So measure for 320 for all your assets then your retina ones will simply be twice the size