android 截图
2016-02-12 22:22
477 查看
public class ScreenShot { public static Bitmap takeScreenShot(Activity activity) { // View是你须要截图的View View view = activity.getWindow().getDecorView(); int width1 = activity.getWindow().getDecorView().getWidth(); int height1 = activity.getWindow().getDecorView().getHeight(); 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, 25, 320, 455); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height1-statusBarHeight); view.destroyDrawingCache(); return b; } public 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 (Exception e) { e.printStackTrace(); } } }
相关文章推荐
- Android Studio如何导入jar,so,以及第三方的开源库?
- Android使用setCustomTitle()方法自定义对话框标题
- Android实现百度地图截图
- Android:支持多选的本地相册
- 支付宝咻一咻怎么用 Android帮你实现咻一咻
- Android中常出现的内存泄漏情况分析
- Android 的Drawable
- Android 实现点击两次BACK键退出应用
- Android中常见IPC方法总结
- 一、Android编码规范
- Android 开发笔记——通过 Intent 传递类对象
- android、Java下判断两个String是否相等 、EditText输入是否为空,
- Android ImageButton的使用。
- Android:30分钟弄明白Touch事件分发机制
- Unable to create Debug Bridge:Unable to start adb server
- ANDROID_MARS学习笔记_S02_004_ExpandableListActivity
- Android Wear开启通过蓝牙调试后,显示"主机:已断开连接"解决方法
- Android TV Studuy1-2
- android:从另外一个activity中返回数据
- Android使用简单的Service