网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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://bjjierui.cn/article/jphpp.html

其他资讯