我正在从android中的视图创建一个图像,并使用下面的代码在其底部添加另一个图像
CardView card_view = (CardView) tmps.findViewById(R.id.card_view);
Bitmap b = Bitmap.createBitmap(card_view.getWidth(), card_view.getHeight() + 112, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
card_view.draw(c);
c.translate(card_view.getWidth() / 2 - 51, card_view.getHeight() + 10);
Drawable d = context.getResources().getDrawable(R.drawable.share_logo);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
d.draw(c);
现在,当我将图像添加到底部(R.drawable.share_logo)时,它将出现在黑色背景上。如何创建一个白色填充矩形作为整个画布的背景?
答案 0 :(得分:0)
试试这段代码:
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
return b;
}
CardView card_view = (CardView) tmps.findViewById(R.id.card_view);
Bitmap bitmap = loadBitmapFromView(card_view);