2016-03-05 73 views
-1

我創建針對Android上的視圖的圖像圖像和添加其他圖像到它的底部下方創建從View

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

試試這個代碼:

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); 
+0

BHAI,視圖圖像中正確地來了。圖像R,drawable.share_logo我添加到圖像視圖的底部有一個黑色的背景。我需要白色的。 –