Created
June 29, 2017 10:21
-
-
Save hayukleung/db65f30e2278e3a92efaa250e780e4ff to your computer and use it in GitHub Desktop.
获取一个 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
/** | |
* 获取一个 View 的缓存视图 | |
* | |
* @param view | |
* @return | |
*/ | |
private Bitmap getCacheBitmapFromView(View view) { | |
final boolean drawingCacheEnabled = true; | |
view.setDrawingCacheEnabled(drawingCacheEnabled); | |
view.buildDrawingCache(drawingCacheEnabled); | |
final Bitmap drawingCache = view.getDrawingCache(); | |
Bitmap bitmap; | |
if (drawingCache != null) { | |
bitmap = Bitmap.createBitmap(drawingCache); | |
view.setDrawingCacheEnabled(false); | |
} else { | |
bitmap = null; | |
} | |
return bitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment