Created
July 21, 2014 14:52
-
-
Save angeldevil/60c3df9559168f96d59b to your computer and use it in GitHub Desktop.
Convert a view to bitmap without displaying it
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 convertViewToBitmap(View view) { | |
view.destroyDrawingCache(); | |
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), | |
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | |
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); | |
view.setDrawingCacheEnabled(true); | |
return view.getDrawingCache(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment