开发者

SVG to Bitmap at runtime conversion in Android [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Close开发者_开发技巧d 7 years ago.

Improve this question

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.


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;


Are you trying to do this in a native Android app? Or in the Android browser using JavaScript?

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

  • canvg
  • fabric.js

Once you use these libraries to render the SVG to canvas, you could further grab a static image file from the canvas. Refer to this Stack Overflow thread for more detail on that second step.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜