SVG for Bitmap during conversion to Android

How to convert SVG (scalable vector graphics) to Bitmap at runtime on Android?

Please, if possible, provide me with the exact code snippet or exact links. I am completely new to Android app development.

+6
source share
2 answers

Follow the instructions of svg-android to get PictureDrawable from your SVG file. Then you need to create a Bitmap from the size of the PictureDrawable and pass it to the Canvas . When Canvas now draws a Picture from a PictureDrawable , the current bitmap that 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; 
+8
source

Are you trying to do this in your own Android application? Or in an Android browser using JavaScript?

If you are in a later camp, you can use JavaScript to parse SVG and render the results into an HTML5 canvas element (which is a raster surface). There are two libraries that can help you:

Once you use these libraries to render the SVG to the canvas, you can additionally capture a static image file from the canvas. See this thread for more details on this second step .

-1
source

Source: https://habr.com/ru/post/895948/


All Articles