Android截屏的简单实现

来源:互联网 发布:淘宝改版 编辑:程序博客网 时间:2024/06/11 08:38

代码如下:

private void screenshot()    {        // 获取屏幕        View dView = getWindow().getDecorView();        dView.setDrawingCacheEnabled(true);        dView.buildDrawingCache();        Bitmap bmp = dView.getDrawingCache();        if (bmp != null)        {            try {                // 获取内置SD卡路径                String sdCardPath = Environment.getExternalStorageDirectory().getPath();                // 图片文件路径                String filePath = sdCardPath + File.separator + "screenshot.png";                File file = new File(filePath);                FileOutputStream os = new FileOutputStream(file); //输出流                bmp.compress(Bitmap.CompressFormat.PNG, 100, os); //对图片进行压缩                os.flush();  //刷新                os.close();  //关闭            } catch (Exception e) {            }        }    }
0 0
原创粉丝点击