I\'m trying to inflate a layout and use that to set a bitmap on an image view. Then, I\'m adding that imageview to a linear layout and displaying the linear layout. Here\'s
You cant get bitmap on the views or layout is not being inflated.
Layout will only getting inflated after OnCreate()
.
1.Get bitmap on Button_Clicked(View view){}
2.Or using a Handle()
to post delaying your get bitmap
3.Make sure drawing cache is created using view.buildDrawingCache();
/***
*
* @param flameLayout/linearLayout...
* @param width
* @param height
* @return
*/
public static Bitmap viewToBitmap(View view, int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
Convert a layout to Bitmap.
FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();