Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add all sizes of image asset in Android Studio with a PDF or Vector file

In iOS development with Xcode it is really convenient because you can add an image asset or launcher icon with one .pdf file and it generates all the necessary sizes automatically. The .pdf file can be created with Adobe Illustrator or a similar program that makes vector graphics.

Rather than sit there and export every size of icon/image asset one at a time, is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own? Or in general, is there a way to accomplish the same thing in some way?

I have seen other posts where people suggest using an online tool that takes your .png image and lets you download a .zip with all of the different image sizes, but by definition, that method will not result in crisp and high quality image assets. You always want to go from a vector.

like image 491
Micro Avatar asked Dec 28 '15 18:12

Micro


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.

What is image asset in Android Studio?

Android Studio includes a tool called Image Asset Studio that helps you generate your own app icons from material icons, custom images, and text strings. It generates a set of icons at the appropriate resolution for each pixel density that your app supports.


1 Answers

is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own?

Use File > New > Vector Asset in Android Studio 1.5 and higher. This will let you import an SVG file. Android Studio will attempt to convert it into a vector drawable resource, with varying degrees of success. If you are using a recent version of the Android Plugin for Gradle (1.5.0 or higher should work AFAIK), the build tools will also generate PNGs from the vector drawables for use on older devices (Android 4.4 and earlier).

but by definition, that method will not result in crisp and high quality image assets

You do not have much of a choice on older devices. There are a few deprecated backports of VectorDrawable floating around that you can try to use, but Google abandoned theirs.

You always want to go from a vector.

Not necessarily. Please bear in mind that not everybody has high-end mobile devices. Rendering SVG or other vector artwork is comparatively expensive, which is why Android did not directly support it (and still does not directly support SVG itself).

like image 175
CommonsWare Avatar answered Sep 20 '22 00:09

CommonsWare