简单实现手机、电脑相互操作

news/2024/10/15 12:00:45/

1、从手机截图到sdcard

2、将图片导出到PC

3、从PC加载图片

4、开启定时器

5、操作电脑UI事件

1、

    private static void takeScreenshot(String path) {long t1 = System.currentTimeMillis();String command = "adb devices"; // 替换为你需要执行的shell命令String command1 = "adb shell screencap -p /sdcard/screencap.png"; // 替换为你需要执行的shell命令String command2 = "adb pull /sdcard/screencap.png " + path; // 替换为你需要执行的shell命令String command3 = "adb shell rm /sdcard/screencap.png"; // 替换为你需要执行的shell命令String command4 = "rm -rf " + path; // 替换为你需要执行的shell命令try {
//            Process process = Runtime.getRuntime().exec(command);Process process1 = Runtime.getRuntime().exec(command1);Process process2 = Runtime.getRuntime().exec(command2);Process process3 = Runtime.getRuntime().exec(command3);
//            Process process4 = Runtime.getRuntime().exec(command4);//            {
//                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
//                String line;
//                while ((line = reader.readLine()) != null) {
//                    System.out.println(line);
//                }
//            }{BufferedReader reader = new BufferedReader(new InputStreamReader(process1.getInputStream()));String line;while ((line = reader.readLine()) != null) {System.out.println(line);}}
//            {
//                BufferedReader reader = new BufferedReader(new InputStreamReader(process2.getInputStream()));
//                String line;
//                while ((line = reader.readLine()) != null) {
//                    System.out.println(line);
//                }
//            }
//            {
//                BufferedReader reader = new BufferedReader(new InputStreamReader(process3.getInputStream()));
//                String line;
//                while ((line = reader.readLine()) != null) {
//                    System.out.println(line);
//                }
//            }
//            {
//                BufferedReader reader = new BufferedReader(new InputStreamReader(process4.getInputStream()));
//                String line;
//                while ((line = reader.readLine()) != null) {
//                    System.out.println(line);
//                }
//            }long t2 = System.currentTimeMillis();System.out.println("takeScreenshot Exited with code: 时间:" + (t2 - t1));} catch (Exception e) {e.printStackTrace();}}

2、

static BufferedImage getImage(String folderPath) {long t1 = System.currentTimeMillis();File folder = new File(folderPath);File[] listOfFiles = folder.listFiles();BufferedImage bufferedImage = null;for (File file : listOfFiles) {if (file.isFile() && file.getName().toLowerCase().endsWith(".png") || file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".jpeg")) {try {bufferedImage = ImageIO.read(file);// 1080*2340System.out.println("getImage " + bufferedImage.getWidth());System.out.println("getImage " + bufferedImage.getHeight());} catch (IOException e) {e.printStackTrace();} finally {long t2 = System.currentTimeMillis();System.out.println("getImage : 时间:" + (t2 - t1));return bufferedImage;}}}return null;
}

3、

    static JFrame jFrame;static JLabel jLabel;static void showFrame(BufferedImage screenFullImage) {// 1080*2340jFrame = new JFrame("Screen Capture");jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);jLabel = new JLabel("");//设置标签大小,这种可以设计成自己想要大小jLabel.setBounds(0, 0, 500, 900);//将图片进行转换添加到标签当中  这个是工具类,具体参考下面给出代码setImgSize(screenFullImage, jLabel);jFrame.add(jLabel);jFrame.pack();
//        frame.setSize(300,600);     // 设置JFrame的尺寸jFrame.setVisible(true);}

4、

private static final int DELAY = 400; // 帧间隔,单位毫秒public static void main(String[] args) {String path = "/Users/Desktop/command/png2";takeScreenshot(path);BufferedImage image = getImage(path);showFrame(image);Timer timer = new Timer(DELAY, new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {System.out.println("actionPerformed");takeScreenshot(path);BufferedImage screenFullImage = getImage(path);setImgSize(screenFullImage, jLabel);}});timer.start();
}

5、效果图:

6、


http://www.ppmy.cn/news/1539420.html

相关文章

Python知识点:基于Python技术,如何使用TensorFlow进行自动驾驶模型训练

开篇,先说一个好消息,截止到2025年1月1日前,翻到文末找到我,赠送定制版的开题报告和任务书,先到先得!过期不候! 使用TensorFlow进行自动驾驶模型训练的Python技术详解 自动驾驶技术是人工智能领…

Spring Boot课程支持:智能答疑系统

1系统概述 1.1 研究背景 如今互联网高速发展,网络遍布全球,通过互联网发布的消息能快而方便的传播到世界每个角落,并且互联网上能传播的信息也很广,比如文字、图片、声音、视频等。从而,这种种好处使得互联网成了信息传…

SaaS架构:中央库存系统架构设计

大家好,我是汤师爷~ 近年来,越来越多的零售企业大力发展全渠道业务。在销售额增长上,通过线上的小程序、直播、平台渠道等方式,拓展流量变现渠道。在会员增长方面,通过多样的互动方式,全渠道触达消费者&am…

二、创建型(工厂方法模式)

工厂方法模式 概念 工厂方法模式是一种创建型设计模式,它定义了一个创建对象的接口,但由子类决定要实例化的类。工厂方法将实例化逻辑推迟到子类,使得代码更加灵活和可扩展。 应用场景 产品系列:当系统需要创建一系列相关或相互…

Linux操作系统小项目——实现《进程池》

文章目录 前言:代码实现:原理讲解:细节处理: 前言: 在前面的学习中,我们简单的了解了下进程之间的通信方式,目前我们只能知道父子进程的通信是通过匿名管道的方式进行通信的,这是因…

Go-知识依赖GOPATH

Go-知识依赖GOPATH 1. 介绍2. GOROOT 是什么3. GOPATH 是什么4. 依赖查找5. GOPATH 的缺点 1. 介绍 早期Go语言单纯地使用GOPATH管理依赖,但是GOPATH不方便管理依赖的多个版本,后来增加了vendor,允许把项目依赖 连同项目源码一同管理。Go 1.…

PL/SQL Developer如何连接Oracle数据库(汉化)

简介 PL/SQL Developer是一种用于Oracle数据库开发的集成开发环境(IDE)。它提供了一个可视化的界面,使开发人员能够方便地编写、调试和执行PL/SQL代码。PL/SQL Developer还具有其他功能,如数据库对象浏览器、SQL编辑器、数据导入…

P2056 [ZJOI2007] 捉迷藏 题解

P2056 [ZJOI2007] 捉迷藏 题面: 题目描述 Jiajia 和 Wind 是一对恩爱的夫妻,并且他们有很多孩子。某天,Jiajia、Wind 和孩子们决定在家里玩捉迷藏游戏。他们的家很大且构造很奇特,由 N N N 个屋子和 N − 1 N-1 N−1 条双向走廊…