Android开发如何将view转化成图片

来源:互联网 发布:使用ant进行java开发 编辑:程序博客网 时间:2024/06/03 18:19
// 获取指定Activity的截屏,保存到png文件    public 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;//        L.e(""+statusBarHeight);        // 获取屏幕长和高        int width = activity.getWindowManager().getDefaultDisplay().getWidth();        int height = activity.getWindowManager().getDefaultDisplay().getHeight();        // 去掉标题栏        // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);        int hh = statusBarHeight+50;        L.e("截取的高---"+statusBarHeight+"屏幕的高--"+height);        Bitmap b = Bitmap.createBitmap(b1, 0, hh, width, height -hh);        view.destroyDrawingCache();        L.e("Thresh"+ "takeScreenShot:            截图成功");        return b;    }
3 0
原创粉丝点击