Created
May 14, 2019 03:53
-
-
Save esabook/20a6eeea9d5164e390550f50a60df16f to your computer and use it in GitHub Desktop.
get bitmap from android view
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
/** | |
* get {@link Bitmap} object from {@link View} | |
* | |
* @param view | |
* @return | |
*/ | |
public 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) { | |
bgDrawable.draw(canvas); | |
} else { | |
canvas.drawColor(Color.WHITE); | |
} | |
// draw the view on the canvas | |
view.draw(canvas); | |
return returnedBitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment