android 保存当前屏幕或者view为图片bitmap
2013-12-03 11:36
429 查看
转自:/article/2474054.html
public class ScreenShot { public static Bitmap takeScreenShot(Activity activity) { // View是你需要截图的ViewView view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1= view.getDrawingCache();// 获取状态栏高度 Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top;// 获取屏幕长和高 int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay() .getHeight();// 去掉标题栏 Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);view.destroyDrawingCache(); return b; }
<span style="color:#ff0000;">//新增方法</span>
public static Bitmap takeViewShot(View view) { // View是你需要截图的View view.setDrawingCacheEnabled(true);view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache();// 获取View长和高 int width = view.getWidth(); int height = view.getHeight();Bitmap b = Bitmap.createBitmap(b1, 0, 0, width, height); view.destroyDrawingCache(); return b;}private static void savePic(Bitmap b, File filePath) { FileOutputStream fos = null;try { fos = new FileOutputStream(filePath); if (null != fos) {b.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close();} } catch (FileNotFoundException e) { } catch (IOException e) { }}public static void shoot(Activity a, File filePath) { if (filePath == null) { return;} if (!filePath.getParentFile().exists()) { filePath.getParentFile().mkdirs(); } ScreenShot.savePic(ScreenShot.takeScreenShot(a), filePath); }}
相关文章推荐
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将View界面保存成图片bitmap
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byt
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Android中图片处理(压缩 保存 显示 截屏 视图View转为图片Bitmap)函数工具类
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Android:实现截取当前屏幕图片并保存至SDCard
- 【Android】Android实现截取当前屏幕图片并保存至SDCard
- [Android] 一个将当前屏幕保存为图片文件的类(简单说就是抓屏)
- Android—将Bitmap图片保存到SD卡目录下或者指定目录
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Android—将Bitmap图片保存到SD卡目录下或者指定目录
- Android—将Bitmap图片保存到SD卡目录下或者指定目录
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- 【Android】Android实现截取当前屏幕图片并保存至SDCard
- Android如何截取当前View 为图片
- Android webview长按图片保存到本地
- android中保存Bitmap图片到指定文件夹中的方法
- [待完成,不要看]Android 将View保存为图片 View生成长图
- 史上最强Android 开启照相或者是从本地相册选中一张图片以后先裁剪在保存并显示的讲解附源码i