我在应用程序中有一个简单的 VectorDrawable。它来自 android SDK,看起来像这样:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>
我想将它绘制成 400x400 位图,以便缩放以填充位图。目前,当我绘制它时,它仅以 24x24 显示。这是代码:
ImageView imageview = (ImageView) findViewById(R.id.image_view);
VectorDrawable drawable = (VectorDrawable) getResources().getDrawable(
R.drawable.testvector, null);
// drawable.mutate();
int width = 400
int height = 400;
Bitmap mutableImage = Bitmap.createBitmap(
metrics, width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mutableImage);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
imageview.setImageDrawable(drawable);