Multi Resolution background images in Flutter assets - android

In Android we have variety of dpi drawable folders so we add background images in that based on resolution. Same like in iOS we add in 1x, 2x and 3x based on screen sizes. But how we will add multi resolution images in Flutter assets?
Ex:
Android
drawable-hdpi
- login_background.jpeg
drawable-mdpi
- login_background.jpeg
drawable-xhdpi
- login_background.jpeg
drawable-xxhdpi
- login_background.jpeg
drawable-xxxdpi
- login_background.jpeg
How we add multiple drawables in flutter to support multiple screen sizes without image stretching or scaling?

Flutter defines ratios like ios so, for example, you can create a folder named 0.75x under the assets/images for ldpi images. Other densities are as below
Dentisity Flutter pixel ratio
ldpi 0.75x
mdpi 1.0x
hdpi 1.5x
xhdpi 2.0x
xxhdpi 3.0x
xxxhdpi 4.0x
See documentation here

How Flutter handles multi-resolution images is explained here.
It comes basically down to this:
AssetImage understands how to map a logical requested asset onto one that most closely matches the current device pixel ratio. In order for this mapping to work, assets should be arranged according to a particular directory structure: (...)
An example:
.../my_icon.png
.../2.0x/my_icon.png
.../3.0x/my_icon.png

Related

Android - Storing images in mipmap vs drawable folder

As a general rule, when storing image resources for use in an Android project, should they be placed in the res/drawable or the res/mipmap folder?
Apologies for the simple question, I'm relatively new to Android development. The IDE I'm using is Android Studio 1.0.
My rule is that if an image will have noticeable changes in quality when they are scaled up or down depending on the android device should be stored in mipmap folders. Examples of such images would be icons, slider bar scrubbers or custom google map markers. Images that don't get affected by changes in scale can be put in the drawable res folder.
The graphic resources are stored in corresponding folders “drawable”. A store application icons are stored in the folders “mipmap”. To make the icon you have to make the files with the identical name which will be differ by resolution only and will be placed in the correspondent folders “mipmap”. Here are the the dimensions in pixels for each screen density:
LDPI 36×36.
MDPI 48×48.
TVDPI 64×64.
HDPI 72×72.
XHDPI 96×96.
XXHDPI 144×144.
XXXHDPI 192×192.
When the screen density is not important, I create a simple “drawable” folder and I store there all images. If the screen density is important it is possible to calculate the dimensions of the image, based on the ratio of the size of the base image to the appropriate screen ratio. For the base density is taken MDPI (48 × 48):
LDPI — MDPIx0.75.
HDPI — MDPIx1.5.
TVDPI — MDPIx1.33.
XHDPI — MDPIx2.
XXHDPI — MDPIx3.
XXXHDPI — MDPIx4.
At the time of publication in the convenience store (play.google.com), you will need also 512 × 512 icon and picture for advertisment of 1024 × 500.
In the manifest, do not forget to register R.mipmap.your_icon_name (default R.mipmap.ic_launcher) and the system will automatically select the icon under the screen density
Images that don't get affected by changes in scale can be put in the drawable folder.
If you are building different versions of your app for different densities, you should know about the “mipmap” resource directory.  This is exactly like “drawable” resources, except it does not participate in density stripping when creating different apk targets.
Provide at least an xxxhdpi app icon because devices can display large app icons on the launcher.
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.

Resolution in Android app

When I create my Android app i create 6 drawable folders:
drawable-hdpi. // resolution 1.5 x
drawable-mdpi. // resolution 1 x
drawable-xhdpi. // resolution 2 x.
drawable-large. // resolution 2 x.
drawable-xlarge. // resolution 2.5 x.
drawable-xxhdpi. // resolution 3 x.
In every folder i put the same image with different size according to android device resolution and screen size.
Is this correct? or this is insufficient for my android app ?
When i make project in Android Studio it automatically generates the folder structure for drawable- i.e
-- res
| -- drawable-hdpi (for low density screens)
-- drawable-mdpi (for medium density screens)
-- drawable-xhdpi (for high resolution screens)
-- drawable-xxhdpi (for extra high resolution screens)
The drawable-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
I think that the above is more than sufficient for an android application. And actually xxhdpi is more than enough for a high res tab or phone. Please go through Supporting Multiple Screens.
First, it's not necessary to put all the same images with different size in every folder. If you put the full set of images in drawable-xxhdpi folder, the system will re-size the image for other density automatically. Sometimes, some image may lost important details while re-sizing, then you should redesign a proper image for the density and put in the corresponding folder, not ALL images.
Second, xlarge/large/normal/small are the size of screen, ldpi/mdpi/hdpi/xhdpi/xxhdpi are the density of screen, the resolution is the combinations of size and density.
Finally, you may prepare just one set of image in res/drawable-xxhdpi folder, then design different layout for different screen size in res/layout-*** folders, just set different dp in width/height/margin etc..
Reference: https://developer.android.com/guide/practices/screens_support.html

android resources folder naming

So i have a very stupid question. I am new to Android and trying to understand how the resources folder work.
I see that I need subfolders with ldpi, mdpi, hdpi, xhdpi, xxhdpi naming but does the naming of the actual image need to be different?
For example, If I have an image names icon.png.
In iOS: mdpi would be icon.png, xhdpi would be icon#2x.png and xxhdpi would be icon#3x.png.
Do I need to give different naming in Android?
If I put icon.png in 5 different folders with 5 different sizes, would there be a name conflict?
It would be very good if someone can explain it.
I read all standard android explanations but I want to make sure with someone who has actually done it.
Thanks for your time.
Directory Naming:
You do not need to provide a different suffix to your image file name for different screen sizes in Android like you do in iOS. The file name should be exactly the same for all the images of different sizes.
However, you need to follow Google's guidelines/conventions for directory naming. Images are called 'drawables' in Android.
Under the 'res' directory, place each image under a directory called drawable-<suffix>. Replace the <suffix> with the screen density qualifier (i.e., mdpi, hdpi, xhdpi, xxhdpi etc.)
Google recommends that you also create a directory called drawable (with no suffix) for default images. These default images will be used as fallback when Android does not find a specific image size for the user's device.
Example directory structure:
res/
drawable/
icon.png
background.png
drawable-mdpi/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
drawable-xhdpi/
icon.png
background.png
drawable-xxhdpi/
icon.png
background.png
Image Size Ratios:
The correct way to create images for different screen densities is by starting at a base image size for mdpi.
Say for example your base icon size is 48px x 48px. Then:
mdpi: 48px x 48px (1x)
hdpi: 72px x 72px (1.5x)
xhdpi: 96px x 96px (2x)
xxhdpi: 144px x 144px (3x)
xxxhdpi: 192px x 192px (4x)
References:
Directory structure:
http://developer.android.com/guide/topics/resources/providing-resources.html
For size ratio comparison (mdpi vs hdpi vs xhdpi vs xxhdpi) go to:
http://developer.android.com/design/style/iconography.html

Android Application Background Resolution

I want to design a background for android application using Photoshop , let's say I have Samsung S4,So I set the resolution to the maximum of that device which is 1080x1920 and 441dpi
Now,my question is where should i insert it in what subfolder of Resources and depending on what we choose that folder
-drawable-hdpi
-drawable-ldpi
-drawable-mdpi
-drawable-xhdpi
-drawable-xxhdpi
What image feature decides on which folder image should be in?
Hopefully, this image will show you which category it falls into:
As you can see everything larger than 400dpi is xxhdpi, so you should place it there.
Also check out the DisplayMetrics page.
EDIT: To answer your last question. There isn't any image feature that determines where it belongs, the folders are simply used to load images with different resolutions onto different screens. For example if the picture containing text has high resolution and you place it on a low density screen, the text would be (physically) too small to read. So you place a higher resolution image in hdpi or xhdpi folder and resize it so it has smaller resolution and place it in ldpi and mdpi folders.
Please refer to this, it is from google!
http://developer.android.com/training/multiscreen/screendensities.html
You should put on drawable-xxhdpi folder.
A brief explanation about the drawable resources:
The drawable resources are, by default, divided in 6 generalized groups based on its pixel density:
ldpi: Low density drawables (~120 dpi)
mdpi: Medium density drawables (~160 dpi)
hdpi: High density drawables (~240 dpi)
xhdpi: XHigh density drawables (~320 dpi)
xxhdpi: XXHigh density drawables (~480 dpi)
xxxhdpi: XXXHigh density drawables (~640 dpi)
The scaling ration between these drawables should be 3:4:6:8:12:16
You only need to provide density-specific drawables for bitmap files (.png, .jpg, or .gif) and Nine-Path files (.9.png). If you use XML files to define shapes, colors, or other drawable resources, you should put one copy in the default drawable directory (drawable/).
Even if you don't provide alternative drawable resources for the different groups of density, the Android system will find the best matching drawable and scale it for you. But is recommended to provide alternative drawable resources in order to ensure to always have smooth drawables in all devices.
You might want to take a look here.

Android drawable mdpi

I am working on a Android Project.
I put the images (320*480) into the mdpi -folder. There are some information in Android developer site that 480*800 tablets(7") also takes images from the mdpi- folder. When the 7" tablet takes images form that mdpi- folder it become smaller. There is only one mdpi- folder so how do i exactly manage it .
You should read the Android developer documentation on Providing Alternative Resources.
From my answer to this similar question:
The ImageView will render the image inside of it at the correct resolution for the device. As per the documentation on providing resources, you must make sure that you provide resources at the correct DPI for each of the resolution types. Android will pick the best resource resolution for you, but if only one resource exists then it will pick that one and try to render at the device resolution.
So, find out the correct DPI for your device, and add the image (at the correct DPI) into that folder and it should appear at the correct size. If the image is placed in the wrong folder then it will appear a different size. Another useful link is the Density Independence documentation.
Note: let's assume your device is an HDPI device. The res/drawables/drawable-hdpi folder might not exit in your project but you can just add it in manually.
Don't mix up screen size with screen density. There are qualifiers related to screen size (e.g. small, normal, large, ...) and qualifiers related to density (e.g. ldpi, mdpi, ...).
You can even combine these qualifiers, for example in drawable-normal-mdpi you can put resources that will be used on devices with normal screen (phones) with a mdpi density.
you should create ldpi, hdpi, xhpi folder too. And you need to copy your image with same name by calculating its ratio.
ldpi - mdpi - hdpi - xhdpi
3 4 6 8
There is a 3:4:6:8 scaling ratio between the four primary densities
(ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in
mdpi, 18x18 in hdpi and 24x24 in xhdpi.
If you decide that your image resources don't look good enough on a
television or other certain devices and want to try tvdpi resources,
the scaling factor is 1.33*mdpi. For example, a 100px x 100px image
for mdpi screens should be 133px x 133px for tvdpi.

Categories

Resources