Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Vs PNG on Android [closed]

Which is the best way of dealing with images in Android. Recently in Android Lollipop We had given support for SVG(Scalable Vector Graphics) concept. Which is the best way of working with images to support all resolutions PNG(placing images in particular drawable resources) or SVG(Small file sizes that compress well, Scales to any size without losing clarity (except very tiny)).

like image 980
sravanalakshmi.sunkara Avatar asked Nov 03 '14 07:11

sravanalakshmi.sunkara


People also ask

Which is better SVG or PNG for Android?

You will still need PNG images for older platforms, so the ideal workflow is to have vector-based source images that you export to PNG for various DPI buckets and convert to VectorDrawable format for API 21 devices using a project like svg2android.

When should I use SVG instead of PNG?

Transparency. PNGs and SVGs support transparency — so they're both excellent choices for online logos and graphics. It's worth noting that PNGs are one of the best choices for a raster-based transparent file. If you're working with pixels and transparency, PNGs are a better option than SVGs.

Can SVG be used in Android?

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.

When should you use SVG files?

SVG files tend to store images more efficiently than common raster formats as long as the image is not too detailed. SVG files contain enough information to display vectors at any scale, whereas bitmaps require larger files for scaled-up versions of images — more pixels use up more file space.


2 Answers

Lollipop (API 21) does not support SVG. It support a subset of SVG path drawing functionality through the VectorDrawable class. This class is not currently supported by appcompat, so it is only available on API 21.

You will still need PNG images for older platforms, so the ideal workflow is to have vector-based source images that you export to PNG for various DPI buckets and convert to VectorDrawable format for API 21 devices using a project like svg2android.

like image 74
alanv Avatar answered Sep 23 '22 13:09

alanv


You can use Android Support Library 23.2 or higher. The VectorDrawableCompat class in the Support Library allows you to support VectorDrawable in Android 2.1 (API level 7) and higher.For this you need to change your build.gradle file before you run Vector Asset Studio, as described in Support Library Backward Compatibility.

//For Gradle Plugin 2.0+  android {    defaultConfig {      vectorDrawables.useSupportLibrary = true     }  }      //For Gradle Plugin 1.5 or below     android {       defaultConfig {         // Stops the Gradle plugin’s automatic rasterization of vectors         generatedDensities = []       }       // Flag notifies aapt to keep the attribute IDs around       aaptOptions {         additionalParameters "--no-version-vectors"       }     } 

In order to support Vector Drawable and Animated Vector Drawable on devices running Android versions prior to version 5.0 (API level 21), VectorDrawableCompat and AnimatedVectorDrawableCompat are available through two new Support Libraries: support-vector-drawable and animated-vector-drawable, respectively.

Android Studio 1.4 introduced limited compatibility support for vector drawables by generating PNG files at build time. However, the vector drawable and animated vector drawable support Libraries offer both flexibility and broad compatibility — it's a support library, so you can use it with all Android platform versions back to Android 2.1 (API level 7+). To configure your app to use vector support libraries, add the vectorDrawables element to your build.gradle file in the app module.

like image 44
Abhishek Joshi Avatar answered Sep 23 '22 13:09

Abhishek Joshi