ic_business_white_36px,ic_business_white_24px,将这些矢量绘图转换为位图时,它们看起来大小相同,如24dp图标,如何有效地转换它们以便它们有自己的大小?我使用下面的代码将我的矢量drawable转换为位图,我试图在谷歌地图中显示它们。感谢!!!
Drawable drawable = ContextCompat.getDrawable(getActivity(), drawableId);
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable)drawable).getBitmap();
}
int width = drawable.getIntrinsicWidth();
width = width > 0 ? width : 1;
int height = drawable.getIntrinsicHeight();
height = height > 0 ? height : 1;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;