标签:
接上一篇(截图原理)
视频地址:http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=877121&courseId=712011
四、非APK的操作,通过PC端实现截屏操作,及原理
通过adb桥接的方式,调用ddmlib.jar中的IDevice和AndroidDebugBridge类对通过adb连接的设备进行截图,截图之后保存在PC端,可在短时间内截取多张图
五、adb桥接方式实现截屏的代码分析
import java.awt.*; import java.awt.event.*; import java.io.File; import com.android.ddmlib.AndroidDebugBridge; public class PerformAnalysis extends Frame implements ActionListener { private String title = "性能测试工具"; private Button takepicture; private Button getCPUmem; private Label tip; private static TextField picturenum; public PerformAnalysis() { setTitle(title); takepicture = new Button("获取屏幕截图"); takepicture.setSize(150, 100); getCPUmem = new Button("获取内存和CPU"); getCPUmem.setSize(350, 300); picturenum = new TextField("1"); picturenum.setSize(100, 20); tip = new Label("输入截图个数,一秒截一次"); FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT,50,60); setLayout(flowLayout); add(takepicture); add(getCPUmem); add(tip); add(picturenum); takepicture.addActionListener(this); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent we){ System.exit(0); } }); File file = new File("D://lixia//getpicture");if(!file.isDirectory()){//这里的多级目录跟Python中一样,必须得是mkdirs才行,否则根本就建不成功 file.mkdirs(); } AndroidDebugBridge.init(false); setBounds(50, 350, 350, 350); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == takepicture){ ScreenShot screenShot = new ScreenShot(); screenShot.main(); } } public void setNumber(){ picturenum.setText("123"); } public static String getNumber(){ return picturenum.getText().toString(); } public static void main(String[] args){ PerformAnalysis p = new PerformAnalysis(); } }
金阳光测试 |
新浪微博:金阳光woody |
网站地址 |
1、百度搜:金阳光测试 2、官网:www.goldensunshine.cc |
微信公众号 |
标签:
原文地址:http://www.cnblogs.com/keke-xiaoxiami/p/4338354.html