本文转自:http://www.cnblogs.com/pcstart/archive/2011/09/05/2167187.html

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解决坚屏拍照和保存图片旋转90度的问题,并兼容4.0
  4. Android(安卓)主流图片库Picasso Glide Fresco对比分析
  5. android手机客户端上传文件,java servlet服务器端接收并保存到服
  6. Android(安卓)启动过程
  7. android从服务器下载文件(php+apache+win7+MySql)
  8. activity状态的保存和保持(onRetainNonConfigurationInstance和g
  9. Android保存32位BMP格式图片

随机推荐

  1. Ceph分布式存储 - 学习笔记
  2. docker 搭建本地私有仓库
  3. Jenkins参数化构建 - (多任务并串联参数传
  4. 在批处理中调用VBScript(支持获取返回值)
  5. 造成错误“ORA-12547: TNS:lost contact
  6. 你只是想学好linux而已
  7. Ceph分布式存储工作原理 及 部署介绍
  8. centos7下/etc/rc.local文件里配置的开机
  9. Centos7系统下修改主机名、清理linux日志
  10. Centos7.4安装kvm虚拟机(使用virt-manager