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.
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:
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.
发布评论
评论(2)
按照 svg-android 教程获取
PictureDrawable 来自您的 SVG 文件。然后,您需要根据
PictureDrawable
的大小创建一个Bitmap
并将其提供给Canvas
。当Canvas
现在从PictureDrawable
绘制Picture
时,您需要的当前位图将在运行时绘制(创建)。Follow the svg-android tutorial to get a
PictureDrawable
from your SVG file. Then you need to create aBitmap
from the size of thePictureDrawable
and give it to aCanvas
. When theCanvas
now draws aPicture
from thePictureDrawable
, the current bitmap you need is drawn(created) at runtime.您是否尝试在本机 Android 应用程序中执行此操作?或者在Android浏览器中使用JavaScript?
如果您属于后者,您可以使用 JavaScript 来解析 SVG 并将结果渲染到 HTML5 画布元素(这是一个位图表面)。有两个库可以帮助您执行此操作:
使用这些库将 SVG 渲染到画布后,您可以进一步从画布中获取静态图像文件。 请参阅此 Stack Overflow 线程,了解有关该时刻的更多详细信息步。
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:
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.