Android(安卓)屏幕截图 代码
16lz
2023-05-28
本文转自: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();
}
}
更多相关文章
- android实现字体闪烁动画的方法
- Android异步加载图像小结 (含线程池,缓存方法)
- android解决坚屏拍照和保存图片旋转90度的问题,并兼容4.0
- Android(安卓)主流图片库Picasso Glide Fresco对比分析
- android手机客户端上传文件,java servlet服务器端接收并保存到服
- Android(安卓)启动过程
- android从服务器下载文件(php+apache+win7+MySql)
- activity状态的保存和保持(onRetainNonConfigurationInstance和g
- Android保存32位BMP格式图片