public static Bitmap getViewBitmap(View v) {
if (v == null) {
return null;
}
try {
v.clearFocus(); //
v.setPressed(false); //
// 能画缓存就返回false
boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
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 = null;
try {
bitmap = cacheBitmap.copy(Config.RGB_565, true);
} catch (Exception e) {
}
// Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
} catch (OutOfMemoryError ex) {
}
return null;
}
View转换成Bitmap
最新推荐文章于 2022-09-07 17:50:59 发布