通过扫描图片获取pattern图形的九个点的坐标

13 篇文章 0 订阅
   public void testMain() {
  UiObject ptnView = mDevice.findObject(new UiSelector().resourceId("com.android.settings:id/lockPattern"));
                        Rect curPoint;
                        //
                        curPoint = ptnView.getVisibleBounds();
                        
                        // 0: 1080: 540: 994: 1080: 1080: 454
                        mDevice.takeScreenshot(new File("/path/Test.png"));
                        Bitmap bitmap = BitmapFactory.decodeFile("/path/Test.png");
                        int width = curPoint.right;
                        int height = curPoint.bottom;
                        int index = 1;
                        for (int y = curPoint.top; y < height; y++) {
                                int i = 0;
                                for (int x = curPoint.left + 1; x < width; x++) {
                                        int[] colorA = getColorArray(bitmap.getPixel(x - 1, y));
                                        int[] colorB = getColorArray(bitmap.getPixel(x, y));
                                        //
                                        double distan = getDistance(colorA, colorB);
                                        if (distan > 200) {
                                               
                                                x += 50;
                                                i++;
                                                if (i > 2) {
                                                        y += 60;
                                                        break;
                                                }
                                        }
                                }
                        }

                } catch (Exception e) {
                       
                }
        }

        private double getDistance(int[] colorA, int[] colorB) {
                double x = colorA[0] - colorB[0];
                double y = colorA[1] - colorB[1];
                double z = colorA[2] - colorB[2];
                return Math.sqrt(x * x + y * y + z * z);
        }

        public int[] getColorArray(int color) {
                int[] colorArray = new int[3];
                colorArray[0] = color & 0x0ff0000 >> 16;
                colorArray[1] = color & 0x0ff00 >> 8;
                colorArray[2] = color & 0x0ff;
                return colorArray;
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值