Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG to Bitmap at runtime conversion in Android [closed]

How can I convert SVG (Scaleable Vector Graphics) to Bitmap at runtime in Android?

Kindly if possible provide me the exact chunk of code or exact links. I am quite new to Android application development.

like image 529
Hikmat Khan Avatar asked Aug 26 '11 07:08

Hikmat Khan


People also ask

Is SVG supported 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.

How do I use SVG files on Android?

If you want to use some icons that are not present in the list of predefined icons, then you can add your own icon by selecting the Asset Type as Local File(SVG, PSD) and then select the path of your file by clicking on Path. After that click on Next > Finish. Now your icon will be added to your res/drawable folder.

How do I edit SVG files on Android?

To edit an SVG image in Office for Android, tap to select the SVG you want to edit and the Graphics tab should appear on the ribbon. Styles - These are a set of predefined styles you can add to quickly change the look of your SVG file.


1 Answers

Follow the svg-android tutorial to get a PictureDrawable from your SVG file. Then you need to create a Bitmap from the size of the PictureDrawable and give it to a Canvas. When the Canvas now draws a Picture from the PictureDrawable, the current bitmap you need is drawn(created) at runtime.

PictureDrawable pictureDrawable = svg.createPictureDrawable();
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); 
Canvas canvas = new Canvas(bitmap); 
canvas.drawPicture(pictureDrawable.getPicture()); 
currentBitmap = bitmap;
like image 89
TouchBoarder Avatar answered Oct 07 '22 10:10

TouchBoarder