import java.io.FileOutputStream;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Rect;import android.view.View;public class Screenshots {private static Bitmap takeScreenShot(Activity a) {View view = a.getWindow().getDecorView();view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap b1 = view.getDrawingCache();Rect frame = new Rect();a.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);int statusBarHeight = frame.top;int width = a.getWindowManager().getDefaultDisplay().getWidth();int height = a.getWindowManager().getDefaultDisplay().getHeight();// 删除标题栏Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);view.destroyDrawingCache();return b;}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 (Exception e) {e.printStackTrace();}}public static void shoot(Activity a) {savePic(takeScreenShot(a), "/sdcard/xxx.png");}}

更多相关文章

  1. android SpannableString使用详解
  2. android SQLite查询
  3. Android(安卓)代码监控apk安装,卸载,替换
  4. android数据库的简单例子
  5. Android(安卓)RecyclerView 滑动删除例子
  6. Android(安卓)代码监控apk安装,卸载,替换
  7. android,如果某个文件存在就删除
  8. Android(安卓)EditText 只能输入三行文本的实现方法
  9. 删除Android包

随机推荐

  1. 应用Python开发WebService服务端及客户端
  2. 【Python】logging结合decorator模式实优
  3. python接入微博第三方API之2接入用户登录
  4. Python开发利器——wingIDE破解技巧
  5. python subprocess模块 监控子进程的2种
  6. python 的基础 学习 11天 作业题
  7. Django i18n:为{% blocktrans %}块推荐的
  8. [Z] 通天塔导游:各种编程语言的优缺点
  9. Python Homework(2018-05-30,第十三周周三)
  10. Python实战小程序——matplotlib模块画图