阅读更多 android屏幕截图

   
import java.io.FileNotFoundException;      import java.io.FileOutputStream;      import java.io.IOException;            import android.app.Activity;      import android.graphics.Bitmap;      import android.graphics.Rect;      import android.view.View;            public class ScreenShot {          // 获取指定Activity的截屏,保存到png文件          private static Bitmap takeScreenShot(Activity activity){              //View是你需要截图的View              View 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;                System.out.println(statusBarHeight);                            //获取屏幕长和高              int width = activity.getWindowManager().getDefaultDisplay().getWidth();                int height = activity.getWindowManager().getDefaultDisplay().getHeight();                //去掉标题栏              //Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);              Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);              view.destroyDrawingCache();              return b;          }                    //保存到sdcard          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();              }          }                    //程序入口          public static void shoot(Activity a){              ScreenShot.savePic(ScreenShot.takeScreenShot(a), "sdcard/xx.png");          }      }  


  • 大小: 5 KB
  • 查看图片附件

更多相关文章

  1. Android获取手机和应用的相关信息
  2. Android(安卓)Edittext 显示光标 获取焦点 监听焦点
  3. android 获取md5值 google map key申请
  4. Android(安卓)5.1源代码与Nexus设备工厂镜像下载
  5. 【黑马Android】(02)短信发送器/布局演示/android下单位/android
  6. android设置属性
  7. Android从asset中获取drawable
  8. android获取手机信息大全
  9. Android(安卓)获取天气预报

随机推荐

  1. c#开发office办公自动化随笔
  2. Linux安装docker 配置Apache
  3. 分享:选择香港云服务器的一些原因和心得
  4. Docker 镜像制作教程:针对不同语言的精简
  5. 大厂面试 | 百度C++后台开发面试真题汇总
  6. 如何面对变化莫测的css
  7. 详谈程序员到底是做什么工作的(非程序员勿
  8. Springboot+Mybatis+Thymeleaf增加数据的
  9. 收藏|2021年阿里云开源镜像站最热门镜像王
  10. Linux下的源码安装、rpm安装、yum安装三