Creating Drawables for Android

One of the pains for Android development for me is creating drawables in different sizes for various devices. In the past I’d only have a few images at a time to resize so I’d normally just upload them to Android Asset Studio and have the site generate the correct sizes for me.

There are two problems with this approach.  First, I have to upload the files one at a time.  If I have more than 4 files then it becomes a bit of a chore.  Second, I can’t specify what size I want the output.  It always  generates files that are

mdpi 32×32 pixels
hdpi 48×48 pixels
xhdpi 64×64 pixels
xxhdpi 96×96 pixels

Instead of manually editing the images I had (I had a lot) I decided to finally just write an app to handle this for me.  You can find it on GitHub at AndroidIconsResizer.  Right now it is a little barebones but it quickly and easily handles batches of images.

All options are optional so the simples use is to just run it.  If nothing is specified it assumes the current directory for all input or output.  By default the output images are all squares and are 100×100 at the mdpi size.

> AndroidIconResizer

It looks for all the .png files in current directory, resizes them and copies them to the appropriate output directories.  If you ran the above command in the following directory


then the directory would look like this after

        file.png (100 x 100 pixels)
        anotherFile.png (100 x 100 pixels)
        file.png (150 x 150 pixels)
        anotherFile.png (150 x 150 pixels)
        file.png (200 x 200 pixels)
        anotherFile.png (200 x 200 pixels)
        file.png (300 x 300 pixels)
        anotherFile.png (300 x 300 pixels)

It is possible to specify different sizes (heights and widths) for the output images.  All you need to specify is the size you want the mdpi image.  The other sizes are extrapolated based on Google’s iconography recommendations.

> AndroidIconResizer –w 20 –h 50

You can specify the input and output directories just as easily

> AndroidIconResizer –i inputDir –o outputDir

By default the xxxhdpi image isn’t generated since it’s only needed for launcher icons.  You can choose to include it with an option

> AndroidIconResizer –-include-xxxhdpi

Or you can just ask the tool itself for some help:

> AndroidIconResizer –help

Those were all the features I needed today, but I’ll probably be expanding on this app in the future.  Let me know if you’d want any other features.

Happy Coding.

This entry was posted in .NET, Android, C#, Tools and tagged , , , by Josh. Bookmark the permalink.

About Josh

I signed up for a BASIC class in junior high. That got me hooked and pretty soon I started experimenting with harder languages. My college years are a blur of benders hopped up on Perl and Java and that one semester where I sunk so low that I was mainlining Smalltalk. Now I'm a complete C# junky living it one day at a time. Hello, my name is Josh.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>