码迷,mamicode.com
首页 > 移动开发 > 详细

Android-屏幕设备截屏

时间:2014-12-11 18:53:18      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   ar   color   os   使用   sp   

转载请注明:http://www.cnblogs.com/frank-zouxu/p/4158159.html 

今天,公司一个项目在进行中,遇到了屏幕取词的难题,对问题分步处理,首先得解决如何截取设备的屏幕,鉴于Android设备是基于Linux内核的,因此试着找到Android截图命令ScreenCap,在Android4.0的源码中找到:bubuko.com,布布扣

 

其中ScreenCap是基于C++编写的,Screenshot是基于C编写的。这里使用ScreenCap.先进入手机的shell模式,进入命令行:adb shell screencap -h,获得打印信息

usage: screencap [-hp] [-d display-id] [FILENAME]
  -h: this message
  -p: save the file as a png.
  -d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

  

然后我们使用Java代码完成屏幕截取:
            Process sh = Runtime.getRuntime().exec("su", null,null);
                    OutputStream  os = sh.getOutputStream();
                    os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));  
            //在运行时使用shell命令完成截屏操作 os.flush(); os.close(); sh.waitFor();

 至此截屏文件(img.png)就被保存到了sd卡的根目录下了.时间仓促,整个过程叙述的不尽详细,只为记录今日所得。

 

  

 

Android-屏幕设备截屏

标签:android   style   blog   http   ar   color   os   使用   sp   

原文地址:http://www.cnblogs.com/frank-zouxu/p/4158159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!