MonkeyImage模块功能详解

●MonkeyImage模块android

图像处理相关的模块,主要是对截屏生成的图像进行一些操做。主要包括:数组

●MonkeyImage官方详细介绍ui

newimage = MonkeyDevice.takeSnapshot()orm

MonkeyImage是经过MonkeyDevice模块的takeSnapshot()方法来生成屏幕截图,而后生成MonkeyImage对象。对象

●MonkeyImage的方法blog

•convertToBytes //将当前图像转换为字节码图片

•getRawPixel //获取指定坐标位置的像素点,返回值(a,r,g,b)get

•getRawPixelInt //把上面的像素数组以整形返回出来it

•getSubImage //从MonkeyImage中获取子图像io

•sameAs //比较两个MonkeyImage对象的类似度

•writeToFile //将图像写到文件中生成图片文件,通常是png

●代码演示

monkeyrunner

form com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

device=MonkeyRunner.waitForConnection()//获取MonkeyDevice对象

image=device.takeSnapshot() //经过MonkeyDevice对象的takeSnapshot获取屏幕截图

image.convertToBytes()

image.getRawPixel(100,100)

image.getRawPixelInt(100,100)

接下来打开uiautomatorviewer获取计算器上数字6的坐标

subimage=image.getSubImage((543,895,267,293))                         

subimage.writeToFile('6.png','png')

tools目录下就能看到6.png图片

接下来获取计算器上数字9

subimage2 = image.getSubImage((543,602,267,293))

subimage2.writeToFile('9.png','png')

tools目录下就能看到9.png图片

接下来比较6.png和9.png两个子对象

subimage.sameAs(subimage2, 0.9) //0.9表示类似度

ture就表示两个图片类似

相关文章
相关标签/搜索