Пример #1
0
  public void compileScreenShot() {
    createOutputDirStructure();
    if (!screenshotcompiled) {
      try {
        int travDiviser = 100;
        BufferedImage shot = ResourceHelper.getImageResource(googleScreenShot);
        int shotWidth = shot.getWidth();
        int shotHeight = shot.getHeight();
        int travXUnit = Math.max(shotWidth / travDiviser, 1);
        int travYUnit = Math.max(shotHeight / travDiviser, 1);
        Color bg =
            new Color(
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_RED)),
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_GREEN)),
                Integer.parseInt(
                    ResourceHelper.getGoogleProperty(Constants.KEY_GOOGLE_BACKGROUND_COLOR_BLUE)));
        Color col;
        ArrayList<Integer> topList = new ArrayList<>();
        ArrayList<Integer> btmList = new ArrayList<>();
        boolean lastLineMatched = true;
        for1:
        for (int y = 0; y < shotHeight; y++) {
          for2:
          for (int x = 0; x < shotWidth; x += travXUnit) {
            col = new Color(shot.getRGB(x, y));
            if (!col.equals(bg)) {
              if (lastLineMatched) {
                topList.add(y);
                lastLineMatched = false;
              }
              continue for1;
            }
          }
          if (!lastLineMatched) {
            btmList.add(y - 1);
            lastLineMatched = true;
          }
        }

        Rectangle rect = null;
        boolean newRectInserted = false;
        ArrayList<GrabbedImagePosition> grabbedImagePoss = new ArrayList<>();
        int colnum, sno = 0;
        loop1:
        for (int i = 0; i < topList.size(); i++) {
          lastLineMatched = true;
          int maxTop = topList.get(i);
          int maxBtm = btmList.get(i);
          travYUnit = Math.max((maxBtm - maxTop) / travDiviser, 1);
          colnum = 0;
          loop2:
          for (int x = 0; x < shotWidth; x++) {
            loop3:
            for (int y = maxTop; y <= maxBtm; y += travYUnit) {
              col = new Color(shot.getRGB(x, y));
              if (!col.equals(bg)) {
                if (lastLineMatched) {
                  newRectInserted = false;
                  rect = new Rectangle(x, maxTop, 0, maxBtm - maxTop + 1);
                  lastLineMatched = false;
                }
                continue loop2;
              }
            }
            if (!lastLineMatched) {
              rect.width = x - rect.x;
              GrabbedImagePosition gip = new GrabbedImagePosition(sno++);
              gip.setBounds(rect);
              gip.setRownumber(i);
              gip.setColnumber(colnum++);
              grabbedImagePoss.add(gip);
              lastLineMatched = true;
              newRectInserted = true;
            }
          }
          if (!newRectInserted) {
            rect.width = shotWidth - rect.x;
            GrabbedImagePosition gip = new GrabbedImagePosition(sno++);
            gip.setBounds(rect);
            gip.setRownumber(i);
            gip.setColnumber(colnum++);
            grabbedImagePoss.add(gip);
            newRectInserted = true;
          }
        }

        int maxY, maxX;
        loop1:
        for (GrabbedImagePosition gip : grabbedImagePoss) {
          rect = gip.getBounds();
          travXUnit = Math.max(rect.width / travDiviser, 1);
          lastLineMatched = true;
          maxY = rect.y + rect.height;
          maxX = rect.x + rect.width;
          loop2:
          for (int y = rect.y; y < maxY; y++) {
            loop3:
            for (int x = rect.x; x < maxX; x += travXUnit) {
              col = new Color(shot.getRGB(x, y));
              if (!col.equals(bg)) {
                if (lastLineMatched) {
                  rect.y = y;
                  lastLineMatched = false;
                }
                continue loop2;
              }
            }
            if (!lastLineMatched) {
              rect.height = y - rect.y;
              lastLineMatched = true;
            }
          }
        }
        setGrabbedImagePositions(grabbedImagePoss);
        screenshotcompiled = true;
      } catch (Exception ex) {
        ResourceHelper.errLog("Compiler > compileScreenShot() > Error %s", ex);
      }
    }
  }