graphicsmagick Image Resizing
Posted on December 23rd, 2013
The Android runtime attempts to display images appropriate to the platform on which it is running. A developer can provide multiple versions of the same image with each version having a different original size. Regardless of the original image selected by the runtime, the image is ultimately rendered at the size specified by explicit or implicit constraints. This allows an app to render normal 1:1 images (“drawables”), retina-compatible 2:1 images, etc..
More information regarding Android support for varying screen sizes and densities can be found here
To scale images to different sizes I use graphicsmagick , a popular fork of the also popular imagemagick. The graphicsmagick site provides installation instructions, but if you have a mac then the easiest installation method by far is to use homebrew.
homebrew install graphicsmagick
Example of scaling an image, assume that the original image is larger and the image is being scaled down:
gm convert soccer_ball.png -resize 112x112 soccer_ball2.png
Example of changing the image background to a transparent background:
gm convert soccer_ball.png -background none soccer_ball2.png
Android project folder layout for resources:
|src/main/res/drawable-xxhdpi||Extra Extra High|