Skip to content

Instantly share code, notes, and snippets.

@joshskeen
Created August 19, 2016 17:42
Show Gist options
  • Save joshskeen/17131e9581a27d8ba5c74619f4862fec to your computer and use it in GitHub Desktop.
Save joshskeen/17131e9581a27d8ba5c74619f4862fec to your computer and use it in GitHub Desktop.
public static Bitmap getBitmapFromView(View view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return returnedBitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment