SVG to Bitmap at runtime conversion in Android

Hikmat Khan picture Hikmat Khan · Aug 26, 2011 · Viewed 8.3k times · Source

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.

Answer

TouchBoarder picture TouchBoarder · Feb 10, 2013

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;