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
總結
以上是生活随笔為你收集整理的android颜色选择状态,androidUiAutomator如何根据颜色判断控件的状态的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android透明activity,An
- 下一篇: html中collapse代码怎么写,面