我正在尝试缩放从svg-android-library获得的可绘制图片。我可以创建drawable但不知道如何缩放它。
这是我尝试过的代码:
Drawable drawable = svg.createPictureDrawable();
int size = 108;
Bitmap img = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(img);
//resize drawable here according to screen width
drawable = new ScaleDrawable(drawable, 0, size*2, size*2).getDrawable();
drawable.setBounds(0, 0, size*2, size*2);
drawable.draw(canvas);
有什么建议吗?
答案 0 :(得分:1)
我用过
Picture picture = svg.getPicture();
然后用一个新的Rect绘制它,它将拉伸它以适应新的Rect
canvas.drawPicture(picture, newRect);