博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android自动化工具Monkeyrunner使用(三)
阅读量:4050 次
发布时间:2019-05-25

本文共 1812 字,大约阅读时间需要 6 分钟。

     本章开始介绍下MonkeyrunnerAPI, 以便了解其具体的使用。

MonkeyImage  takeSnapshot()截取当前设备的屏幕, 并获得当前图片, 返回一个monkryimage对象。

Captures the entire screen buffer of this device, yielding a screen capture of the current display.

Returns
  • A object containing the image of the current display.

E.g.  截取当前界面,返回一个对象

short_begin = device.takeSnapshot()

这个对象有5中方法可以调用:

Methods
string ( string format)
Converts the current image to a particular format and returns it as a
string that you can then access as an
iterable of binary bytes.
tuple ( integer x, integer y)
Returns the single pixel at the image location (x,y), as an a
tuple of
integer, in the form (a,r,g,b).
integer ( integer x, integer y)
Returns the single pixel at the image location (x,y), as a 32-bit
integer.
( tuple rect)
Creates a new
MonkeyImage object from a rectangular selection of the current image.
boolean ( other, float percent)
Compares this
MonkeyImage object to another and returns the result of the comparison. The
percent argument specifies the percentage difference that is allowed for the two images to be "equal".
void ( string path, string format)
Writes the current image to the file specified by
filename, in the format specified by
format.

其中经常使用的为 sameAs(MonkeyImage other, float percent) , writeToFile(string path, string format)

sameAs(MonkeyImage other, float percent): 是对截取的image对象的比较, 不足之处是不能把手机界面和电脑上的图片进行比较

Compares this MonkeyImage object to another and returns the result of the comparison. The percent argument specifies the percentage difference that is allowed for the two images to be "equal".

short_begin = device.takeSnapshot()

short_end = device.takeSnapshot()

print short_end.sameAs(short_begin, 1.0)

writeToFile (string filename, string format): 保存当前截取的图片, 需要选择路径和格式。格式可以选择png, bmp, jpg等。

short_begin.writeToFile('d:\shotbegin.png','png')

转载地址:http://ewjci.baihongyu.com/

你可能感兴趣的文章
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>
C/C++中关于动态生成一维数组和二维数组的学习
查看>>
JVM最简生存指南
查看>>
JVM并发机制探讨—内存模型、内存可见性和指令重排序
查看>>
持续可用与CAP理论 – 一个系统开发者的观点
查看>>
nginx+tomcat+memcached (msm)实现 session同步复制
查看>>
c++字符数组和字符指针区别以及str***函数
查看>>
c++类的操作符重载注意事项
查看>>
c++模板与泛型编程
查看>>
WAV文件解析
查看>>
WPF中PATH使用AI导出SVG的方法
查看>>
WPF UI&控件免费开源库
查看>>
QT打开项目提示no valid settings file could be found
查看>>
Win10+VS+ESP32环境搭建
查看>>