Skip to content

Instantly share code, notes, and snippets.

@grumpyshoe
Created December 1, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grumpyshoe/d65a286ce87bb7965abf17b5a030055c to your computer and use it in GitHub Desktop.
Save grumpyshoe/d65a286ce87bb7965abf17b5a030055c to your computer and use it in GitHub Desktop.
How to make Bitmap from view
public static Bitmap loadBitmapFromView(View v) {
b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
if (v.getMeasuredHeight() <= 0) {
v.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
c = new Canvas(b);
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.draw(c);
return b;
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment