Last active
September 19, 2016 15:57
-
-
Save Cassie-von-Clausewitz/672ce68f01cf37e8367406091a1de59f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Bitmap getBitmapFromView(View view) { | |
//Define a bitmap with the same size as the view | |
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); | |
//Bind a canvas to it | |
Canvas canvas = new Canvas(returnedBitmap); | |
//Get the view's background | |
Drawable bgDrawable = view.getBackground(); | |
if (bgDrawable != null) { | |
//has background drawable, then draw it on the canvas | |
bgDrawable.draw(canvas); | |
} else { | |
//does not have background drawable, then draw the window background on the canvas | |
canvas.drawColor(ContextCompat.getColor(view.getContext(), R.color.window_background)); | |
} | |
// draw the view on the canvas | |
view.draw(canvas); | |
//return the bitmap | |
return returnedBitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment