现在的位置: 首页 > 综合 > 正文

Andorid截屏代码

2012年09月08日 ⁄ 综合 ⁄ 共 719字 ⁄ 字号 评论关闭

编辑器加载中...

 可以去除信息栏
1     private Bitmap shot(Activity activity) {
2 // View是你需要截图的View
3 View view = activity.getWindow().getDecorView();
4 view.setDrawingCacheEnabled(true);
5 view.buildDrawingCache();
6 Bitmap b1 = view.getDrawingCache();
7
8 // 获取状态栏高度
9 Rect frame = new Rect();
10 activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
11 int statusBarHeight = frame.top;
12 Log.i("TAG", "" + statusBarHeight);
13
14 // 获取屏幕长和高
15 int width = activity.getWindowManager().getDefaultDisplay().getWidth();
16 int height = activity.getWindowManager().getDefaultDisplay().getHeight();
17 // 去掉标题栏
18 // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
19 Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
20 view.destroyDrawingCache();
21 return b;
22 }

抱歉!评论已关闭.