资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

MonkeyImageAPI实践全记录-创新互联

1.    背景

鉴于网上使用MonkeyImage的实例除了方法sameAs外很难找到,所以本人把实践各个API的过程记录下来然自己有更感性的认识,也为往后的工作打下更好的基础。同时也和上一篇文章《MonkeyDevcie API 实践全记录》起到相互呼应的作用。

创新互联公司是一家专注于网站设计、成都网站建设与策划设计,池州网站建设哪家好?创新互联公司做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:池州等地区。池州做网站价格咨询:18982081108

因为并没有MonkeyRunner的项目背景,所以这里更多的是描述各个API是怎么一回事,而不是描述在什么场景下需要用到。也就是说是去回答What,而不是How。

首先我们先看下官方给出的MonkeyImage的API描述,对比我现在反编译的最新的源码是一致的:

Return Type

Methods

Comment

string

convertToBytes (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

getRawPixel (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

getRawPixelInt (integer x, integer y)

Returns the single pixel at the image location (x,y), as a 32-bit integer.

MonkeyImage

getSubImage (tuple rect)

Creates a new MonkeyImage object from a rectangular selection of the current image.

boolean

sameAs (MonkeyImage other, float percent)

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

void

writeToFile (string path, string format)

Writes the current image to the file specified by filename, in the format specified by format.

2.      String convertToBytes(string format)

2.1  示例

img = device.takeSnapshot()  png1 = img.convertToBytes()  png2 = img.convertToBytes()  bmp = img.convertToBytes('bmp')  jpg = img.convertToBytes('JPG')  gif = img.convertToBytes('gif')  raw = img.convertToBytes('raw')  invalid = img.convertToBytes('xxx')  #is the 2 pngs equal? print "Two png is equal in bytes:",png1 == png2  #is the png equals to bmp? print "png and bmp is equal in bytes:", png1 == bmp  #is the jpg eqals to the raw? print "jpg and bmp is equals in bytes:",jpg == bmp  #is the jpg eqals to the xxx? print "jpg is a valid argument:",jpg != invalid  #is the gif eqals to the xxx? print "gif is a valid argument:",gif != invalid  #is the bmp eqals to the xxx? print "bmp is a valid argument:",bmp != invalid  #is the raw equas to xxxx? aims at checking whether argument 'raw' is invalid like 'xxx' print 'raw is a valid argument:',raw != invalid  #would invalid argument drop to png by default? print 'Would invalid argument drop to png by default:',png1 == invalid
输出:

MonkeyImage API 实践全记录

2.2 分析

除了默认的png,常用格式jpg,gif都支持,但bmp格式无效,至于还支持什么其他格式,尝试跟踪了下代码,没有找到想要的结果

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享题目:MonkeyImageAPI实践全记录-创新互联
文章来源:http://cdkjz.cn/article/jphpp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220