`
貌似掉线
  • 浏览: 256581 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

在PC端进行android截屏的多种方法

阅读更多
昨晚意外的发现在PC端进行截屏的方法相当多,在android sdk的tools里面有大量的jar包可以利用。
第一种方法:
这里使用AndroidDebugBridge及其相关类进行截屏,使用的jar包是ddmlib.jar,在android sdk的tools文件夹内。
代码如下(以下代码抽取自互联网并经修改过):
/*
 * @(#)ScreenShot.java	       Project:lianmeng
 * Date-Time:2013-10-11 下午1:08:36
 *
 * Copyright (c) 2013 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package pw.msdx.lianmengassistant;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.RawImage;

/**
 * copy from http://bbs.csdn.net/topics/390502035. modify by Geek_Soledad
 */
public class AdbUtil {
	public static IDevice connect() {
		// init the lib
		// [try to] ensure ADB is running
		String adbLocation = System.getProperty("com.android.screenshot.bindir"); //$NON-NLS-1$
		if (adbLocation != null && adbLocation.length() != 0) {
			adbLocation += File.separator + "adb"; //$NON-NLS-1$
		} else {
			adbLocation = "adb"; //$NON-NLS-1$
		}

		AndroidDebugBridge.init(false /* debugger support */);

		AndroidDebugBridge bridge = AndroidDebugBridge
				.createBridge(adbLocation, true /* forceNewBridge */);

		// we can't just ask for the device list right away, as the internal
		// thread getting
		// them from ADB may not be done getting the first list.
		// Since we don't really want getDevices() to be blocking, we wait
		// here manually.
		int count = 0;
		while (bridge.hasInitialDeviceList() == false) {
			try {
				Thread.sleep(100);
				count++;
			} catch (InterruptedException e) {
				// pass
			}

			// let's not wait > 10 sec.
			if (count > 100) {
				System.err.println("Timeout getting device list!");
				return null;
			}
		}

		// now get the devices
		IDevice[] devices = bridge.getDevices();

		if (devices.length == 0) {
			System.out.println("No devices found!");
			return null;
		}

		return devices[0];
	}

	public static BufferedImage screenShot(IDevice device) {
		RawImage rawImage;
		try {
			rawImage = device.getScreenshot();
		} catch (Exception ioe) {
			System.out.println("Unable to get frame buffer: " + ioe.getMessage());
			return null;
		}

		// device/adb not available?
		if (rawImage == null)
			return null;

		// convert raw data to an Image
		BufferedImage image = new BufferedImage(rawImage.width, rawImage.height,
				BufferedImage.TYPE_INT_ARGB);

		int index = 0;
		int IndexInc = rawImage.bpp >> 3;
		for (int y = 0; y < rawImage.height; y++) {
			for (int x = 0; x < rawImage.width; x++) {
				int value = rawImage.getARGB(index);
				index += IndexInc;
				image.setRGB(x, y, value);
			}
		}
		return image;
	}

	/**
	 * Grab an image from an ADB-connected device.
	 */
	public static boolean screenShotAndSave(IDevice device, String filepath) throws IOException {
		boolean result = ImageIO.write(screenShot(device), "png", new File(filepath));
		if (result) {
			System.out.println("file is saved in:" + filepath);
		}
		return result;
	}

	public static void terminate() {
		AndroidDebugBridge.terminate();
	}
}


第二种方法:
使用monkeyrunner.jar包,当然还要添加相关jar包。由于新版的API改变,不知道其中参数应该怎么传,未深入去做。

第三种方法,使用chimpchat.jar及相关jar包(common.jar,guava-13.0.1.jar),代码大致如下:
		AdbBackend adb = new AdbBackend();
		IChimpDevice device = adb.waitForConnection();
		ImageIO.write(device.takeSnapshot().createBufferedImage(), "png", new File("E:\\tmp.png"));
		device.dispose();
		if (adb != null) {
			adb.shutdown();
		}

但是执行之后,程序没有停止下来,不知如何才能使其终止。
0
0
分享到:
评论

相关推荐

    91手机助手 v6.10.5.1180.zip

    91助手V5版本是一款通过电脑管理iPhone、iPad、Android Phone、Android Pad等多种智能设备的PC端软件,全面支持苹果iOS、安卓Android等智能手机操作系统。使用91助手V5版,通过电脑即可轻松管理智能手机,下 载海量...

    droidAtScreen-1.4.rar

    它集截图、录像等多种功能于一体。但发现之前的版本都不能适用于android8.1,于是下载github开源代码https://github.com/ribomation/DroidAtScreen1.git, 经过修改,已经可以支持android8.1,手上只有android6.0和...

    手立视客户端 v1.3.zip

    9、多客户端支持:客户端全覆盖,包括:手机端(Android和IOS)、PAD(Android和IOS)、PC端和网页版,为用户随时随地查看视频提供最便捷的方式。 10、多账号支持:单机最多可以绑定15个账号,同时查看视频数不限。...

    91手机助手 v3.3.7.1031 优雅黑金版

    【基本介绍】91助手3 iOS&安卓版,是一款通过电脑管理iPhone、iPad、Android Phone、Android Pad等多种智能设备的PC端软件,全面支持苹果、安卓等智能手机操作系统。使用91助手3 iOS&安卓版,通过电脑即可轻松管理...

    工作宝(企业即时通讯软件) v4.0.zip

    工作宝是一款面向企业用户的可打电话、开电话会议、发消息、协同办公的企业即时通讯软件,公有云版本永久免费,无任何功能限制,...【PC端、Android端界面UI重构】界面优化,更加清晰明确,使用体验更爽快。 工作宝截图

    开源免费 APK 编辑器 APK Editor Studio 1.4.0 中文多语免费版.zip

    多种便捷工具将帮助您轻松更改应用程序图标,应用程序标题,自动签名 APK 并将其安装在设备上。对于所有想要修改其 APK 文件各种参数的用户,APK Editor Studio 免费版是一种用户友好的解决方案。 APK 反编译工具 ...

    APK 编辑器 APK Editor Studio 1.4.0 中文多语.zip

    多种便捷工具将帮助您轻松更改应用程序图标,应用程序标题,自动签名 APK 并将其安装在设备上。对于所有想要修改其 APK 文件各种参数的用户,APK Editor Studio 免费版是一种用户友好的解决方案。 APK 反编译工具 ...

    Download Smartnews For PC Window 10-crx插件

    它提供了在应用程序的普通版中不存在的特殊和唯一功能,并且在其所有用户可以访问隐藏模拟位置并防止特定应用程序的屏幕截图。它为您提供像歌曲等音频流,来自许多公认的网络的新闻,实时体育评论,以及20多种语言的...

    91助手 3.3.7.1023版

    91手机助手3 iPhone&安卓版,是一款通过电脑管理iPhone、iPad、Android Phone、Android Pad等多种智能设备的PC端软件,全面支持苹果、安卓等智能手机操作系统。使用91手机助手3 iPhone&安卓版,通过电脑即可轻松管理...

    小娱wifi助手 v1.4.325.zip

    防恶性攻击、篡改,防虚假WiFi与钓鱼WiFi帮你优化网速,升级体验 含智能WiFi管理功能,特色小娱导航 “精彩发现”与“个人管理”配合,应有尽有 多终端,跨平台,不受约束 支持苹果(IOS)/安卓(Android) ...

    WICED Sense1蓝牙智能传感器原理图+PCB源文件+BOM清单-电路方案

    除了本体,Broadcom的WICED Sense套件还提供了5个微电子机械系统(MEMS),以及1个支持蓝牙4.1的Software Stack,并且面向iOS、Android、Windows和PC全平台。 WICED Sense介绍: WICED Sense开发套件是拥有多种功能的...

Global site tag (gtag.js) - Google Analytics