public static BitmapgetViewBitmap(Viewv){
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();
BitmapcacheBitmap
= v.getDrawingCache();
if (cacheBitmap == null ){
// Log.e(TAG,"failedgetViewBitmap("+v+")",new
// RuntimeException());
return null ;
}
Bitmapbitmap
= Bitmap.createBitmap(cacheBitmap);
// Restoretheview
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
}

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

更多相关文章

  1. 『ANDROID』反射取子类、父类 属性
  2. Android数据缓存
  3. android post get
  4. Android(安卓)返回键退出APP
  5. Android为返回键设置动画效果
  6. android Style应用
  7. 2011.07.12——— android Foreground service
  8. Android中遇到问题:file.delete()不能删除文件
  9. android webview点击返回键返回上一个html

随机推荐

  1. Android的Bluetooth Profile与UUID
  2. Android添加垂直滚动ScrollView
  3. android 圆角图标 和不规则圆角(边框)
  4. [Android Pro] PackageManager#getPackag
  5. 一些非常实用的 Android 开发资源 【转】
  6. android 4.0 for windows 7 开发环境搭建
  7. Android中Gallery的应用
  8. 自定义 SeekBar 样式 详解
  9. Rockie's Android Porting Guide(3)——Add
  10. 关于Android音频、视频录制类MediaRecord