SVG为位图在Android的运行时转换 [英] SVG to Bitmap at runtime conversion in Android
问题描述
我如何转换SVG(可缩放矢量图形),在运行时在Android的位图?
How can I convert SVG (Scaleable Vector Graphics) to Bitmap at runtime in Android?
敬请如果可能的话给我提供code或确切联系的确切块。我是很新的Android应用程序的开发。
Kindly if possible provide me the exact chunk of code or exact links. I am quite new to Android application development.
推荐答案
按照 SVG-的Android 教程从您的SVG文件获得 PictureDrawable
。然后,你需要创建一个位图
从大小 PictureDrawable
,并给它一个帆布
。当画布
现在绘制图片
从 PictureDrawable
,你需要在当前的位图在运行时绘制(创建)。
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;
这篇关于SVG为位图在Android的运行时转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!