public static Bitmap getViewBitmap(View v) {

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) {
// Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
return null;
}
Bitmap bitmap
= Bitmap.createBitmap(cacheBitmap);
// Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
}


//保存到sdcard
// savePic(getViewBitmap(v), "sdcard/xx.png");
private static void savePic(Bitmap b,String strFileName){
FileOutputStream fos
= null;
try {
fos
= new FileOutputStream(strFileName);
if (null != fos)
{
b.compress(Bitmap.CompressFormat.PNG,
90, fos);
fos.flush();
fos.close();
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}

相关文章:

  • 2021-06-22
  • 2021-12-03
  • 2022-01-12
  • 2021-05-31
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-08-02
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2021-11-04
  • 2022-01-20
  • 2021-09-10
  • 2022-02-25
  • 2021-10-22
相关资源
相似解决方案