Created
August 11, 2014 06:11
-
-
Save ixiyang/bd1c416e2f4cdbe5dde6 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 getViewBitmap(View v) { | |
v.clearFocus(); | |
v.setPressed(false); | |
boolean willNotCache = v.willNotCacheDrawing(); | |
v.setWillNotCacheDrawing(false); | |
// Reset the drawing cache background color to fully transparent | |
// for the duration of this operation | |
int color = v.getDrawingCacheBackgroundColor(); | |
v.setDrawingCacheBackgroundColor(0); | |
if (color != 0) { | |
v.destroyDrawingCache(); | |
} | |
v.buildDrawingCache(); | |
Bitmap cacheBitmap = v.getDrawingCache(); | |
if (cacheBitmap == null) { | |
return null; | |
} | |
Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); | |
// Restore the view | |
v.destroyDrawingCache(); | |
v.setWillNotCacheDrawing(willNotCache); | |
v.setDrawingCacheBackgroundColor(color); | |
return bitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment