#2x retina image equivalent in Android - ios

I'm converting a iOS application to android. (using android studio)
I have all my image as ...#2x.png
So, My 2 questions:
1- Can I copy all my #2x to ONLY folder "xhdpi", and android will auto adjust density for the devices?
2- Was "xhdpi" really the equivalent of xcode #2x ?

You should read this as it will give you a good start on the sizes of all your images and it helped me when i was starting out developing for Android http://developer.android.com/guide/practices/screens_support.html
But basically android devices use different DPI images depending on the screen size. If you don't have the DPI that the device uses then it will apply the closest DPI, however this may give a pixilated or stretched look to your app.
There is no DPI that is equal to Retina. The following are some of the screen sizes based off MDPI which is the same size as non-retina.
MDPI = Non-Retina = 100% image
HDPI = 150% image
Retina = 200% image
XHDPI = 225% image
http://www.teehanlax.com/blog/density-converter/
You will need to have a folder in your images folder for each DPI that your app will support. If your going to be working with the latest devices only then you will probally only need HDPI, XHDPI and XXHDPI

Related

iOS: Preparing background images for applications

Mostly every iOS application has a view with an image as background. Is there any image sizing guide out there? For example here is an iOS screen designed in Sketch:
As you can see there is a background image. Now there are lots of Apple devices every application should support. The new iOS 10 supports all devices from iPhone 5 to iPhone 6s Plus. They have different screen sizes and resolutions. When creating Xcode assets, I am giving 3 background images with different sizes - #1x, #2x, #3x. What sizes should they be?
The way I see it you have 2 options:
In here you will find the resolutions of the iPhone's:
You don't need the #1 image since you don't support iPhone 4 and 4s (iOS 10).
#2 is for iPhone 5,5c,5S,6 and 6s so basically you can create #2 image of the highest resolution which is the iPhone 6 and this image will work well for the iPhone 5 family.
Or, you can create an image with resolution for each iPhone and using hard coded logic set the image for each phone.
i.e: if iphone5c { setImage("iphone5cImage") } etc etc..
The simplest solution is to create 1 image with the highest resolution. The #3 is the highest for the iPhone 6S+ and it will look amazing for the rest. Don't forget to set the image view as aspect fill.
Also, don't forget to check this thread: How to handle image scale on all the available iPhone resolutions?. It will give you clues of what exactly you are dealing with. TL;DR, It's the options I wrote.
The background images you only need to give are #2x and #3x, because #1x devices are now long gone in the dusty pages of history.
Speaking of #2x and #3x, the image resolutions you give to the developer should be the same with the highest resolution iPhone that uses that given size.
For #2x, that is the iPhone 6, which is 750x1334, and for #3x, the iPhone 6+ which is 1242x2208.
Down-scaling shouldn't be a problem because the aspect ratios of all iPhones that support iOS 10 are the same(16:9).
Note for Developer(s):
The UIImageView will then down-scale the images appropriately,
provided:
1. you created an image set with the provided #2x and #3x images,
2. correctly constrainted the UIImageView to the edges of the superview, and
3. selected the Content Mode of the UIImageView as Scale to Fill or Aspect Fill.
There is design nuance in full size background images. Mostly if the scale aspect fill good enough for different sizes you need to design only for the biggest device size after that the rest of them scale to fit. Sometimes some part of background needs to remain visible or if want to keep a low memory footprint for small device sets you need to create smaller alternatives.
Whenever you make a decision with the design size of asset you need to create #3x,#2x variants.
One more thing I need to point out about vector designs. If your design is made only with vectors you can choose pdf vector export. Storyboards can accept vector assets and they are doing very good when scaling in full backgrounds.
I use background images in my Apps. To solve this problem I use one image that has the resolution to cover all iPhones and all the iPads except the large one.
The image size is 2048x2048 points or 1024x1024 pixels at #2x to cover the 9.7 inch iPad.
The image is compressed JPG to keep the size down. Note that I allow it to scale for iPhone 6 Pluse (#3x) and 12.7 inch iPad Pro (#2x) as the quality doesn't seem to be affected.
I can justify the scaling for the larger devices, because if I provided image for the 12.7 inch iPad Pro, it will be 5464x4096 points (#2x) and 2732x2048 pixels and then the JPG compression would have to be so high (if I wanted to keep the size down), that the quality of the image was low anyway compared with scaling.
If you need high quality try both JPG and PNG for comparison, because the PNG becomes very large for complex images, but gives the best quality.
If you still have the same problem then you can try this one. For this you have to add only one image with good resolution and below code..
UIImage *bgImage = [UIImage imageNamed:#"art_background_star#3x.jpg"];
CGSize screenSize = [UIScreen mainScreen].bounds.size;
UIGraphicsBeginImageContextWithOptions(screenSize, NO, 0.f);
[bgImage drawInRect:CGRectMake(0.f, 0.f, screenSize.width, screenSize.height)];
UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIColor *backgroundColor = [UIColor colorWithPatternImage:resultImage];
self.view.backgroundColor = backgroundColor;
There are 3 kinds of Apple Devices (iPhone and iPad) that is
Normal device which terms to 1 pixel = 1 point#1x (Older iPhone and iPad devices)
Retina device which terms to 4 pixels(2 x 2) = 1 point#2x (iPhone 5+)
Retina iPhone6 and iPad which terms to 9 pixels (3 x 3) = 1 point#3x (iPhone6+)
For iOs 10 that will not support iPhone 4s so you only require #2x and #3x images.
As you can see above attached image iPhone 6 also support #2x Scale so use image size for #2x is of 750*1334 and for #3x is of 1242*2208 with image mode.
Take a look at the page on documentation, there is Static Launch Screen Images, and you can catch sizes from there.
You can get a device screen size, using
CGSize screenSize = [UIScreen mainScreen].bounds.size // (Objective-C)
let screenSize: CGSize = UIScreen.mainScreen().bounds.size // (Swift)
And after you can programmatically select an image you want, from set of an images from the bundle. Or to make a big one image for resizing, using knowledges from documentation, and to resize an image accordingly. Or...your choice.
Different "sizes" #2x, #3x is scale.
And here is the nice explanation.

Using less Images for non-retina, retina and retina HD (#1x, #2x, #3x) for Universal Apps

To support iOS 7 to 8 on universal devices, I have to make 4 copies of the same image in different size.
For the iPhones
image#2x.png (iphone 4s,5,5s,6)
image#3x.png (iphone 6+)
For the iPads
image.png (ipad 2, ipad mini 1)
image#2x.png (ipad 3, 4, ipad mini 2, ipad Air)
The images are really bloating the app size.
Is it ok to just use 1 image size, the largest one of the set and scale to fit in the uiimageview and use the image view to scale down the image on the smaller screens?
imageView.contentMode = UIViewContentModeScaleAspectFit;
or is it absolutely necessary to have all 4 copies at different sizes?
It works on all the devices on the simulator and on a retina iPad 3, but I have no way of actual testing on other devices and am afraid that the images may not display.
Has anyone tried using 1 large image instead of the set of copies?
Yes, you can theoretically use the largest resolution image and have the UIImageView scale the image down using mode Aspect Fit.
The only drawback is the older phones that don't support retina also are less performant. For example, when using images on cells of a UITableView and scrolling, the device has to load the large image, then scale the image down, and scroll it at the same time, and it will stutter on old, slower devices.
So, perhaps just use multiple images in list views (should just be thumbnails and are tiny anyway, or just use the smaller images here), but don't worry about larger images that stay on the screen and don't scroll.
Make sure you load images in list views using methods that allow caching like imageNamed:.
As long as you take into consideration the performance penalties involved in scaling down the images, you can use just the largest image and scale it down to fit.
By the way, yes I've used this technique in real live apps in the App Store.
Another technique I've seen is to include lower quality images (1x or 2x) and if you run it on a higher resolution device (2x or 3x), automatically download high resolution images from the web. Maybe be nice about it and only download them on wifi.

Using Non-Retina UIImage for Retina display device

When i started working on my game app i didn't know i should create retina/non-retina #2x, #3x, #1x images. I just created the images with no #1x, #2x, #3x at the end of png file. So since my images are currently called image.png, it's considered a non-retina image i know now. Example is I made an image 25x35 in png. In Storyboards i decided to resize the image and i made it 35x40 because it looks better for iPhone5 than 25x35. My issue is even for 1x i'd have to re-create 40 images from scratch for #3x first and then use Prepo app to automatically downsize to #2x #1x scales. I tested my non-retina images on iPhone 4s/5/5s/6/6+ simulators and iPad 2, Air, Retina simulators and they all look the same and great, and app works well. No blurs or issues. Can I just use my image.png for Retina device as well? Would Apple allow this?
If this is an in-app image, and not the application icon, then yes, you can just use Any resolution image. You can use UIImageView and set contentMode on it to perform AspectFit, ensuring the image will be the same size on every screen type, and also will not get stretched.
myImageView.contentMode = UIViewContentModeScaleAspectFit;
Example: The simplest way to resize an UIImage?
This will preserve the aspect ratio of the image when fitting it to the image view container.
I would provide the image itself with the highest resolution required (#3x), but without #3x in the name, and let UIImageView scale it down to the required size for the other two resolutions.
There is a performance hit in doing this. If it doesn't degrade your scroll performance, go for it.
So basically: start with a high res image and scale down. Do not scale up a low res image, because it won't look crisp. And keep the same aspect ratio so it doesn't stretch.
You will not get rejected for doing this to in-app images.
If all of your assets have the #3x postfix then the App Store recognizes your app as being optimized for the iPhone 6 (together with correctly sized startup images or .xib / .storyboard). Using bigger images for non-retina or normal retina screen causes your RAM usage to increase and slightly taxes your GPU more but for simple apps this isn't a real concern.

Xcode iPad resolution in landscape mode

I`m new at iOS development. I have seen that the new iPad 3 have an 1536x2048 resolution. And I asked from my designer that all the design should be in that resolution, but now i see that i have to resize every image, button and background to fit xcodes story board. How in xcode i can set the development resolution to 1536*2048?
You don't. Xcode uses points to reference pixels and automatically uses the correct graphics depending on the device. You have to make two copies of your image, "image" and "image#2x".
You do all of your development with "image" and iOS will automatically use the #2x version if the device is retina.
Your HD images should have #2x suffix. See "Specifying High-Resolution Images in iOS" section of Resource Programming Guide,
1536x2048 is the resolution of the screen (in pixel) but in xcode you are working with points. So ipad3 has still 1024x786 points (the same as in ipad2) but you can go to the point 0.5 for example.

iPad image sizes

I am creating an application for iPad, the images I have available from graphic designer are
really big, almost twice the size.
According to the graphic designer, the images were created keeping in mind iPad 3.
So if I reduce my image size to half and use them, is it going to make any difference on iPad3?
Or there is no difference and it will be compatible in both.
I am new to iOS development and not sure about the image resizing in detail.
Thanks in advance.
You will have two versions of every image where one is double the size of the other and the operating system will decide which version to use. You just need to name the images correctly.
Images for ipad3 will have #2x within the name. Example
image.png <--- non retina ipad
image#2x.png <------ retina ipad (ipad3)
Here is a post explaining this more: Preparing your iPhone App for Higher Resolutions

Resources