I have some icons in SVG format, and want to convert them to Android png drawables, in the following sizes: drawable-mdpi
, drawable-hdpi
, drawable-xhdpi
, drawable-xxhdpi
and drawable-xxxhdpi
.
What's the easiest way to convert an SVG to drawable pngs?
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. The major advantage of using a vector drawable is image scalability.
Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.
You can import an SVG file as a VectorDrawable in Android Studio, follow these steps : "Right-click" on the res folder and select new > Vector Asset. Select the Local File option and browse to your . svg file.
Question might be a bit outdated, but I searched Internet and didn't find any good solution. So I wrote a simple bash script which does conversion of SVG as well as raster image formats.
Here it is: https://gist.github.com/tntclaus/18f4fe7e8540f1cb283d2c7d8ad21d69
Usage:
./generateAndroidDrawables.sh <image.file> <dp>
It requires at least ImageMagic, which on OS X can be installed via brew
or macports
. Unfortunately ImageMagic poorly converts SVG, so I added support of Inkscape. If Inkscape is not installed, script falls back to ImageMagic conversion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With