Created
December 1, 2016 13:50
-
-
Save grumpyshoe/d65a286ce87bb7965abf17b5a030055c to your computer and use it in GitHub Desktop.
How to make Bitmap from 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
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