android屏幕截图

Java代码
  1. importjava.io.FileNotFoundException;
  2. importjava.io.FileOutputStream;
  3. importjava.io.IOException;
  4. importandroid.app.Activity;
  5. importandroid.graphics.Bitmap;
  6. importandroid.graphics.Rect;
  7. importandroid.view.View;
  8. publicclassScreenShot{
  9. //获取指定Activity的截屏,保存到png文件
  10. privatestaticBitmaptakeScreenShot(Activityactivity){
  11. //View是你需要截图的View
  12. Viewview=activity.getWindow().getDecorView();
  13. view.setDrawingCacheEnabled(true);
  14. view.buildDrawingCache();
  15. Bitmapb1=view.getDrawingCache();
  16. //获取状态栏高度
  17. Rectframe=newRect();
  18. activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
  19. intstatusBarHeight=frame.top;
  20. System.out.println(statusBarHeight);
  21. //获取屏幕长和高
  22. intwidth=activity.getWindowManager().getDefaultDisplay().getWidth();
  23. intheight=activity.getWindowManager().getDefaultDisplay().getHeight();
  24. //去掉标题栏
  25. //Bitmapb=Bitmap.createBitmap(b1,0,25,320,455);
  26. Bitmapb=Bitmap.createBitmap(b1,0,statusBarHeight,width,height-statusBarHeight);
  27. view.destroyDrawingCache();
  28. returnb;
  29. }
  30. //保存到sdcard
  31. privatestaticvoidsavePic(Bitmapb,StringstrFileName){
  32. FileOutputStreamfos=null;
  33. try{
  34. fos=newFileOutputStream(strFileName);
  35. if(null!=fos)
  36. {
  37. b.compress(Bitmap.CompressFormat.PNG,90,fos);
  38. fos.flush();
  39. fos.close();
  40. }
  41. }catch(FileNotFoundExceptione){
  42. e.printStackTrace();
  43. }catch(IOExceptione){
  44. e.printStackTrace();
  45. }
  46. }
  47. //程序入口
  48. publicstaticvoidshoot(Activitya){
  49. ScreenShot.savePic(ScreenShot.takeScreenShot(a),"sdcard/xx.png");
  50. }
  51. }

更多相关文章

  1. android实现签名功能
  2. android屏幕截图
  3. Android有用代码片断(六)
  4. 【Android(安卓)笔记 五】 Android(安卓)Sensor感应器介绍(一)重力
  5. android中的后退键——onBackPressed()的使用
  6. android定位个人当前位置
  7. Android(安卓)获取控件宽高
  8. android 将图片转换成黑白图片
  9. Android实现打电话功能

随机推荐

  1. [置顶] Android(安卓)Wi-Fi Direct 开发
  2. android sdk 基础框架及其功能
  3. 像素点和设备独立像素点的区别
  4. Android(安卓)launcher 桌面抽屉切换动画
  5. Android消息队列模型——Thread,Handler,
  6. 一起学opengl android
  7. 为什么我们可以在非UI线程中更新UI
  8. Android实现使用微信登录第三方APP的方法
  9. 从纪念碑谷 Monument Valley 登陆 Androi
  10. Android中AsyncTask的基本用法