Image sizes for iPhone are incorrect- - ios

I have this image called image.png - I have created it in the 3 differen't sizes.
image#3x.png - 1001x132px
image#2x.png - 668x88px
image.png - 334x44px
What I dont understand is how come the #2x is 668px in width, when the iPhone 5&5S are only 640px wide?
I have designed the #3x using iPhone 6+ screen size.
Could someone please explain?

Let me explain you the difference between the iPhone screens, so you will understand the need of these #?x suffixes.
The first iPhone, and the two after it (3G and 3GS) had the standard display with dimensions w:320, h:480. With the introducing of iPhone 4, Apple also introduced the so called Retina display, which "packs" 4 physical pixels in 1 logical pixel (also called "point"), i.e.:
Now, even though the pixel dimensions of the iPhone 4 are w:640, h:960 (and iPhone 5/5C/5S w:640, h:1136), you still have screen size of w:320, h:480 points (respectively w:320, h:568 for 5/5C/5S). But because the coordinate system of the display uses points instead of pixels, the dimensions and position in points of all UI elements remains the same for every device.
What about the prefixes?
Now, the ratio between point and pixels is called "scale". UIScreen, UIView, UIImage, and CALayer classes have a property called scale, and when you load image with prefix #2x, the scale will be 2.0 and the display will fit 2x2 bitmap pixels from the image in one point. iPhone 6+ uses the #3x suffix because of the Retina HD display, which has scaling factor 3 and the image is afterwards downscaled from rendered 2208 × 1242 pixels to 1920 × 1080 pixels (points on the screen).
The downscaling ratio is 1920 / 2208 = 1080 / 1242 = 20 / 23. That
means every 23 pixels from the original render have to be mapped to 20
physical pixels. In other words the image is scaled down to
approximately 87% of its original size.
(source).
Required image sizes
For example if you want to have an image of green circle in a black square with dimensions w:100, h:100, you will need two more images: one with dimensions w:200, h:200 and one with w:300, h:300, as the system will scale them according to the suffix.
Where to go next
Here is some stuff to read (if I didn't explain it right or easy to understand). My advice: check the link above and the official Apple documentation for further knowledge:
Apple documentation: Supporting high-res devices
Apple documentation: Points vs. Pixels

#2x is using for retina display, like iphone 4, 4s, 5, 5s, 6, ipads ....
The image has 668px in width, I think it use for a view that could have extra area for view, like horizontal scroll view, tutorial pages, or for ipad ... ... or something like that ..
And yes, you're right about the width of retina display, it is just 640px.
Hope this may help.

Related

Understanding Image Size for Different Resolution Screens

I'm having a hard time putting all the information on image sizes for #1x, #2x, and #3x together. I've been using the scene editor in XCode with the scene size being 1334x750 (pixel dimensions of the screen of the iPhone 6). So when I size an image for a sprite in that scene, is that the size I should use for the #2x?
From what I've read in the documentation CGSize uses points, not pixels, so if I have an image that is CGSize(width: 50, height: 50), is this independent of my scene size in the scene editor?
Bottom line question: How does the CGSize dimensions translate to how I export my images for #1x, #2x, and #3x in pixels and what should the PPI be when I export?
Xcode can handle vector images, so you can forget about #2X and #3X images if you are able to export your images as PDF e.g. in Sketches export panel one of the options for export format is PDF, so create your artwork #1X and export as PDF, then in Xcode when you add the image to Assets.xcassets, you can set the images Scales attribute to Single Scale. Xcode will generate the required #2X and #3X images from your vector PDF at build time.
The concept is simple. The size in Storyboard or Interface Builder should be the size of you asset in #1x format.
The retina display ( or the iPhone 6+ #3x size ) does not mean than you have much space than before, it means that you can draw 2 ( or 3 ) pixels where you draw 1 before.
So for a 50x50 px Image View, cou should have 3 assets :
- Image#1x.png ( 50x50 px)
- Image#2x.png ( 100x100 px)
- Image#3x.png ( 150x150 px)
Suppose you have created an image in your assets library consisting of 3 sets of same image, #1x.png having size 50x50 pixels, #2x.png of size 100x100 pixels and #3x.png size 150x150 pixels.
you don't needs to worry about which one to use in your storyboard(because storyboard automatically using #1x.png), and which one to use for the targeted device like as iPhone6, or iphone7, or iPad(because by default programing all hardware finds out their pixels relative required image among those #1x.png, #2x.png and #3x.png)
for further instructions you needs to study Auto layout Programing Guide
you can also view their apple's tutorial videos regarding Auto layout.
mysteries of auto layout part1
mysteries of auto layout part2
#1x and #2x used to relate to the retina graphics change when iPhone 4 came out.
iPhone 3GS was 320x480, iPhone 4 was 640x960. This meant that the points per inch were literally the same, but the ppi was doubled, hence the #2x. When the iPhone 5 came out, the only thing that changed was the height, so the ppi was the same for the width, no problems here.
Then we hit the 6 and 6+. At this point, apple said screw it, try to keep ppi that correlate to previous iPhones without having keep the previous iphones usable area, or provide bigger screen pixels for bigger devices. Now #2x has lost its original meaning
But, to really throw us off, they made the iPhone SE, which went back to the ppi screen size of the iPhone 5, so #2x makes sense again.
Basically, when thinking of the #2x graphics, think about the 1st iPhone resolution size.
Now, you have a choice to make. You can give your apps more/less usable area, you can black box the extra usable area, or you can scale and take some kind of quality loss due to game pixels not being 1:1 with the screen pixels anymore.

How to decide 1x, 2x and 3x image sizes based on the size of the corresponding UIImageView?

My query is in two parts:
1) plain and simple, how do we decide the 1x, 2x and 3x image sizes ?
I found this SO question closest
what-should-be-3x-images-of-100x100 size UIimageView or UIButton
but there is no accepted answer in this so I am a little confused if that is really how it is
So if I have a UIImageView of size, say, 17 X 21
So will my 1x be 17X21, 2x be 34X42 and 3x be 51X63 ?
2) If it is so what the sizes would be in case my UIImageView size also varies as per screen size.
So for iPhone 4s 320X480 if my UIImageView was 17X21, for iPhone 6 375X667 it would be 20X29
So how do I decide my image sizes (1x, 2x & 3x) which are fit for all device sizes?
PS:
Really a big thanks in advance, coz this might sound a very basic question but I have really banged my head a lot over it but can't find a concrete satisfactory answer even after searching and reading a lot.
You should think in points, not pixels.
1
If your UIImageView has the size of 17x21 points then you'll need to provide 3 images 17x21 pixels, 34x42 pixels and 51x63 pixels. The OS will pick the correct one depending on the pixel density of the device the app is running on.
2
One way to decide the size a UI element is using a software like Graphic. You can draw a rectangle representing the screen and the UI element only thinking in points. This should make things easier.
It is a bit late but I understand your problem.
First you need to know the difference between point and pixel.
The point is when you in Xcode.The pixel is when you have the actual size of iPhones screen as pixel.
In 4s, 1 px equal 1 point.
In 5, Se, 6 , 1 point 2 px
in 6s, 7s , 1 point 3 pixel.
I am gonna give you 2 different example to understand this.
Example 1
You want you image 100x100 for all iPhones in Xcode.So you should make :
1x size 100x100 pixel in Ps or Sketch.
2x size 200x200 pixel in Ps or Sketch.
3x size 300x300 pixel in Ps or Sketch.
Another example answers you question.Because you have aspect radio.That means you want your image to be scaled.
You have 17x21 point for 4s then it should be 17x21 pixel.
You have 20x29 point for iPhone 6. It should be 40x58 pixel.
You have something for 6s and 7s so it should be 3 X something.
Because you have aspect ratio and scaled.It does not matter as long as you keep 1x for 4s, 2x for 5, 6, SE, 3x for 6s and 7s.
So you have 40x58 instead 34x42 (17x21) x 2 for iPhone 6.
40x50 for better resolution which Apple recommend.When you use aspect ratio, it sometimes be hard to choose the image size.If you used 32x42 instead 40x58 , there is nothing wrong with this but resolution would be less than 40x58.
Hope It works.

Image.xcassets rendering strangely on simulator

I designed an image on Adobe Illustrator that has H: 100 px and W: 2000 px. When the device is in landscape left, this asset should run across the bottom the of screen and completely cover it from end to end.
As far as I know, the iPhone 6+ is 1080 x 1920. An asset with the width of two thousand should comfortably fit on the bottom, so I must be missing something big here.
I used Prepo to covert my 3x (the one with width of 2000), into 2x and 1x.
The figures are as follows:
3x: 2001 x 102
2x: 1334 x 68
1x: 667 x 34
This set:
Fits: 5s, 5, 4s
Too Short: iPad Retina, iPad Air, iPad 2, 6+, 6
I'm assuming I'm missing some critical aspect of image xcassets because I'm sort of at a loss.
Thank you, and I'm happy to update this with any other details needed.
First thing...
The iPad Air resolution is 2048x1536 and so your image of 2001 pixel width will not fit. Also, iPhone 6+ resolution is 1242x2208 so again that won't fit.
Second...
You shouldn't only be relying on the image size to fit to the screen. You haven't shown what the image is but I imagine that something of that size will be some sort of gradients or something that spreads across the bottom of the screen.
In that case you should be using a sliced image that will resize to be any size regardless of the device resolution.
Third...
If you do rely on the image size then what guarantee do you have that in the future there will not be a device with an even bigger resolution that will break the image again?
Hint... The near future is guaranteed to have a device with a bigger resolution that will break your display.
Summary
Use a resizable image that will stretch to the required size no matter what it is.
Use something like AutoLayout so that the frame of the image view is set by the screen size rather than being set by the image size.

Image size optimizing for newer retina screens

I need to implement some photo uploading function, but I'm a little bit confused because of the pixel/size dimension of the images. I need to display a square cropped image which size in IB is 320 x 320.
I've made a little research, but couldn't find an exact answer. I've checked Instagram, and it uses 640 x 640 pixel images everywhere. How is that possible? The iPhone 6 Plus's screen resolution is bigger then the Full Hd, the width of the screen is 1136 px while an Instagram image is 640 px wide (and doesn't pixelated) . I don't think that they save images for every devices separately.
So UIImageView can display non-retina images on retina screens like this? Or what's the reason why the 640 px is enough?
UIImageView can scale the image you pass to it. So if you were to pass a 640x640 pixel image into a UIImageView that was displayed larger on screen, it would be scaled to fit appropriately. It would scale up and you would lose quality when displayed that way.
As for the IB size being 320x320 points, that doesn't directly translate to pixels. Older devices worked that way, but newer (retina) devices scaled at 2x (including the iPhone 6). So a 320x320 pt UIImageView in IB would actually render at 640x640 pixels. The 6 Plus renders at 3x, so 960x960 pixels.
I'm not sure how you concluded that Instagram was using 640x640 on all devices, but if that is the case, the 6 Plus is scaling images to 960x960 pixels and losing quality. It's possible that the loss isn't noticeable in most cases, but I would guess they request larger images for the larger screen.
http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

Cocoa Point vs Pixel and PPI

Well, I have basically two questions regarding screen resolution in iOS devices.
1) In iOS documentation, on the Point vs Pixels section, it states the coordinates are passed in to framework as points, and that "One point does not necessarily correspond to one pixel on the screen." as found here: https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html
When they are different? Up until now I was assuming they were equal and passing in pixel coordinates. Is this a parameter that changes from device to device?
2) I'm also a little bit confused about PPI. I know what it means on the hardware screen (if a 10" and a 7" display have the same pixel resolution then the 7" display will have a better image quality since the PPI is higher). But what difference it makes if I save a .png with 72ppi or 96 or even 326? Is it just for printing or does it make any difference visually on my screen?
Thanks
On retina devices (iPhone 4, 4S, or 5, and iPad 3 or 4), there are 2 pixels per point. On non-retina devices, there is 1 pixel per point.
Except for the iPhone 5, all iPhones have a screen size of 320x480 points. The retina iPhones have a screen size of 640x960 pixels (but the same point size as the non-retina devices).
When working with images in iOS, it is the pixel size that matters, not the PPI. Just remember that your #2x images should have twice the width and height of the regular, non-retina images.

Resources