code: public static int Maximum(ImageSource fastBitmap, int startX, int startY, int width, int height) {
          int max = 0;
  
          if (fastBitmap.isGrayscale()) {
              for (int i = startX; i < height; i++) {
                  for (int j = startY; j < width; j++) {
                      int gray = fastBitmap.getRGB(j, i);
                      if (gray > max) {
                          max = gray;
                      }
                  }
              }
          } else {
              for (int i = startX; i < height; i++) {
                  for (int j = startY; j < width; j++) {
                      int gray = fastBitmap.getG(j, i);
                      if (gray > max) {
                          max = gray;
                      }
                  }
              }
          }
  
          return max;
      }
docs: Get maximum gray value in the image.
  
  @param fastBitmap Image to be processed.
  @param startX     Initial X axis coordinate.
  @param startY     Initial Y axis coordinate.
  @param width      Width.
  @param height     Height.
  @return Maximum gray.