How to decide 1x size for image? - ios

I have one ImageView but the width and height are not constant. Both will change as per device width and height. (Height of ImageView is 1/3 of screen size and width is complete device width)
Example:
Proper Colors
Height
Width
iPhone SE
375
222.5
iPhone 11 Pro Max
414
298.67
iPhone 12 Pro Max
428
308.67
iPhone 12
390
281.33
As we see, width and height are varying so in this scenario what should be size for 1x image. Once we get 1x size then 2x and 3x sizes we can find easily.
Note: If width and height is fixed then I know how to find 1x, 2x and 3x.
Example: If imageView is 20x20 then, 1x = 20x20, 2x = 40x40, 3x = 60x60, But in above scenario width and height is not constant.

Note: If width and height is fixed then I know how to find 1x, 2x and 3x. Example: If imageView is 20x20 then, 1x = 20x20,2x = 40x40,3x = 60x60
#1x, #2x, #3x has more to do with the pixel density of the screen and not the size of the image. If the same sized image is displayed on a higher resolution screen then iOS will automatically choose a #3x version of the asset. Think of video quality on YouTube, a 720p and 1080p has the same size. But the 1080p video is more clear.
But in above scenario width and height is not constant.
As to dealing with the changing size of the screen, you need to decide before hand how your images should be displayed. This is a UI designing concern. UIImageView has various ContentMode options that you can use. For example,
scaleAspectFit: The option to scale the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
So if you use scaleAspectFit then on larger screen sizes you will have more blank space to the sides of the image.
Also, please take a look at Apple's Human Interface Guidelines for Image Size and Resolution and 1x, 2x and 3x Image Scaling on iOS Explained blog post.
The coordinate system iOS uses to place content onscreen is based on measurements in points, which map to pixels in the display. A standard-resolution display has a 1:1 pixel density (or #1x), where one pixel is equal to one point. High-resolution displays have a higher pixel density, offering a scale factor of 2.0 or 3.0 (referred to as #2x and #3x). As a result, high-resolution displays demand images with more pixels.
When you can fit more pixels on the same screen real-estate, you also need higher resolution images. This is where 1x, 2x and 3x come in. You provide higher resolution image files for the same assets, which are automatically selected by iOS when your app runs on a high-PPI iPhone model.

Related

Image asset size in Xcode interface builder

If I add an image view onto interface builder in Xcode and it has a size of 200 x 100 (size in Xcode), how do I know what size to make the image asset for 1x 2x and 3x.
If I make it 600x300 pixels in photoshop for the 3x and then try to use this image it doesn't look very clear on an iPhone 7 plus so how do I know what resolution the image assets should be for a given image view size
If I add an image view onto interface builder in Xcode and it has a size of 200 x 100 (size in Xcode), how do I know what size to make the image asset for 1x 2x and 3x.
Resolution is a matter of the correspondence between points and pixels. If the desired image size is 200x100 points, then you would provide these three image sizes:
1x: 200x100 pixels
2x: 400x200 pixels
3x: 600x300 pixels
If we are running on, say, a 2x-resolution device, the image will be loaded with its scale set to 2, so that 2 pixels will correspond to 1 point.
Note that you should not attempt to make the 3x image by simply upscaling the 1x image. That will obviously look terrible. You should start with a 600x300 original and downscale to get the 2x and 1x images.

(iOS) What resolution image for an image view with proportional constraints?

If I create an image view that has constraints that are proportional to the size of the screen. I can't decide the exact dimensions of image I need to supply for any of x1, x2 or x3. I understand how image sets work. But it's figuring out the dimensions I need because when I the following code I get slightly different dimensions for every device I test on:
print(imageView.bounds.size.width)
print(imageView.bounds.size.height)
Different x2 devices like the iPhone 5 and iPhone 6 will give me slight differences. But because they receive the same image, will it not look different?
Add an Aspect Ratio constraint on your UIImageView to make sure you don't stretch the image.
Use Aspect Fill or Aspect Fit content mode for UIImageView.
Keep the biggest image for each scale factor (2x, 3x). Basically, there are multiple device resolutions for 2x scale factor, so #2x image should have resolution designed for iPhone 6 and it will be automatically downscaled on smaller devices (iPhone 5/4s). 3x image should have resolution for

Image 1x, 2x and 3x issues on different device in iOS

I have 1x, 2x and 3x images in image assets file like below mentioned image.
But, it were placed 1x image for all devices like below mentioned image.
Am using Xcode 7.3 and iOS 9.3. I created imageview using auto layout. And set Align centre x to superview and Align centre Y to superview.
Any advice / input would be appreciated! Thanks.
This is fine. 3x doesn't mean that your imageview will show three time bigger. It's uses three time bigger resolution. That means if your imageview's size is 50x50 then iphone 6 plus (5.5 inch) requires image with resolution 150x150. If you set 50x50 resolution image to this display then it will not show perfact. That's it. It doesn't mean that 3x image will display 3 time larger then original imageview.
Then also you need your imageview of your size of your image then set UIViewContentModeScaleAspectFill content mode to your imageview with same constraints specified in question!
As #Lion answered this question very well, using 3X does not means your image height and width will increase 3 times.
If you want to resize your image view for bigger device so all you need is to use appropriate autolayout constrains.
follow this if you want to change origin and size of image view with device size(aspect ratio)
And when your size of imageview resize, use the 2/3 times bigger image as imageview for 2X/3X resolution.
Autolayout: origin and size should change according to width and height factor
Check these devices
iPhone 4 and prior #1X
iPhone 4S,5,5S,5C,6,6S,7,7S #2x
iPhone 6+,6S+,7+,7S+ #3x
suppose after applying constraints for bigger screen your image view's size is (50,50) then use a image of size 150,150 for 3X resolution
Make sure your content mode is UIViewContentModeScaleAspectFill and there are no height/width constraints for your UIImageView

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

Resources