SVG为位图在Android的运行时转换 [英] SVG to Bitmap at runtime conversion in Android

查看:588
本文介绍了SVG为位图在Android的运行时转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换SVG(可缩放矢量图形),在运行时在Android的位图?

How can I convert SVG (Scaleable Vector Graphics) to Bitmap at runtime in Android?

敬请如果可能的话给我提供code或确切联系的确切块。我是很新的Andr​​oid应用程序的开发。

Kindly if possible provide me the exact chunk of code or exact links. I am quite new to Android application development.

推荐答案

按照 SVG-的Andr​​oid 教程从您的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆