Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image?

Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image automatically? For example assume that I have a 512x512 image and I want to have different versions of this images for different screen resolutions supported by Android in appropriate folders.


Solution 1:

Option #1: Just ship the -xxhdpi drawables and let Android downsample them for you at runtime (downside: will only work on fairly recent devices, where -xxhdpi is known).

Option #2: Use Android Asset Studio to downsample them for you.

Option #3: Automate the process within a graphics editor, per ssantos' answer.

Option #4: Script yourself a solution, using something like ImageMagick.

Option #5: Use image baker

Solution 2:

Update:

The plugin previously mentioned has been abandoned, but it apparently has an up-to-date fork here.

Old Answer:

I use the Android Studio plugin named Android Drawable Importer:

enter image description here

To use it after installed, right click your res/drawable folder and select New > Batch Drawable Import:

Then select your image via the + button and set the Resolution to be xxhdpi (or whatever the resolution of your source image is).

Solution 3:

Update:

The old way of installing the plugin doesn't work anymore but a fork of original plugin is still functional here. You can still follow this answer after installing the plugin manually.

If you want quick and easy way visit https://www.img-bak.in/ or https://appicon.co/ they work with iOS as well.

I will try to explain the process in step wise basis, so that it will be simple to understand to anyone.

1. Install the plugin manually as provided in the ReadME

2. Restart android studio

3. As you can see in the following screencap, there is only one drawable here

enter image description here

4. Now right-click on the drawable folder and navigate to New>Batch Drawable Import

enter image description here

8.  Now click on the add icon

5. Now select "the Single " image you want different variations of drawables.

enter image description here

6. Now select which dimension the origin image is. If the origin image is xxhdpi like in my case select "xxhdpi " as "Source Resoultion".

7. Now press ok then ok again ..and then it will take few seconds and then you will magically get all the variables of the drawables.enter image description here

enter image description here