Skip to content

Instantly share code, notes, and snippets.

@Rock610
Last active January 10, 2023 09:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rock610/8d64eb2f572558455aef00e2cadd8aba to your computer and use it in GitHub Desktop.
Save Rock610/8d64eb2f572558455aef00e2cadd8aba to your computer and use it in GitHub Desktop.
Converting a view to Bitmap without displaying it
private Bitmap loadBitmapFromView(View v) {
int specWidth = View.MeasureSpec.makeMeasureSpec(900 /* any */, View.MeasureSpec.EXACTLY);
v.measure(specWidth, specWidth);
int questionWidth = v.getMeasuredWidth();
Bitmap b = Bitmap.createBitmap( questionWidth, questionWidth, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawColor(Color.WHITE);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
return b;
}
http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment