android颜色选择状态,androidUiAutomator如何根据颜色判断控件的状态

本人在用UiAutomator做测试的时候,经常会遇到一些控件因为不同的条件显示不同的颜色,在学习了UiAutomator图像处理之后,自己尝试写了一个方法来处理不同颜色控件的区分。分享代码供大家参考。

//根据颜色判断状态

public boolean isBlue(UiObject uiObject) throws UiObjectNotFoundException {

screenShot("test");//截图

String path = "/mnt/sdcard/123/test.png";

Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象

Rect rect = uiObject.getVisibleBounds();

int x = rect.left;

int xx = rect.right;

int y = rect.top;

int yy = rect.bottom;

List blueColor = new ArrayList();

for (int i = x; i < xx; i++) {

for (int k = y;k < yy;k++) {

int color = bitmap.getPixel(i, k);//获取坐标点像素颜色

int red = Color.blue(color);

blueColor.add(red);

}

}

int sum = 0;

for (int i = 0;i 200?true:false;

}

下面是在选择判定值的过程中快速获取某点颜色值的方法:

public int getRedPixel(int x, int y) {

screenShot("test");//截图

String path = "/mnt/sdcard/123/test.png";

Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象

int color = bitmap.getPixel(x, y);//获取坐标点像素颜色

//output(color);//输出颜色值

int red = Color.red(color);

return red;

}

public int getGreenPixel(int x, int y) {

screenShot("test");//截图

String path = "/mnt/sdcard/123/test.png";

Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象

int color = bitmap.getPixel(x, y);//获取坐标点像素颜色

//output(color);//输出颜色值

int green = Color.green(color);

return green;

}

public int getBluePixel(int x, int y) {

screenShot("test");//截图

String path = "/mnt/sdcard/123/test.png";

Bitmap bitmap = BitmapFactory.decodeFile(path);//新建并实例化bitmap对象

int color = bitmap.getPixel(x, y);//获取坐标点像素颜色

//output(color);//输出颜色值

int blue = Color.blue(color);

return blue;

}

public int[] getRGBcolorPixel(int x, int y) {

screenShot("testDemo");

String path = "/mnt/sdcard/123/testDemo.png";

Bitmap bitmap = BitmapFactory.decodeFile(path);

int color = bitmap.getPixel(x, y);

int red = Color.red(color);

int green = Color.green(color);

int blue = Color.blue(color);

int[] rgb = {red, green, blue};

return rgb;

}

技术类文章精选

非技术文章精选

文章来源: www.oschina.net,作者:八音弦,版权归原作者所有,如需转载,请联系作者。

原文链接:https://my.oschina.net/u/3973795/blog/3105339

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值