Skip to content Skip to sidebar Skip to footer

Unable To Get The Bitmap Of A Linearlayout Along With Its Child Views

I am creating the bitmap from a linearlayout with the following code public static Bitmap loadBitmapFromView(View v ) { //Bitmap b = Bitmap.createBitmap( v.getLayoutParams.wid

Solution 1:

You need to measure the view before layout like

v.measure(
      MeasureSpec.makeMeasureSpec(v.getLayoutParams().width,MeasureSpec.EXACTLY),
      MeasureSpec.makeMeasureSpec(v.getLayoutParams().height, MeasureSpec.EXACTLY));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight()
        ,Bitmap.Config.RGB_565);
Canvas c = new Canvas(b);
v.draw(c);

Post a Comment for "Unable To Get The Bitmap Of A Linearlayout Along With Its Child Views"