Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SVG vector to Android multi-density png drawables

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?

like image 699
James Vickery Avatar asked Aug 11 '16 20:08

James Vickery


People also ask

What is vector Drawables in android?

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.

Does Android Studio support SVG?

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.

Can android read SVG files?

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.


1 Answers

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.

like image 68
Клаус Шварц Avatar answered Sep 22 '22 03:09

Клаус Шварц