private static void dumpBlackPoint(URI uri, BufferedImage image, BinaryBitmap bitmap) throws IOException {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int stride = width * 3;
    int[] pixels = new int[stride * height];

    // The original image
    int[] argb = new int[width];
    for (int y = 0; y < height; y++) {
      image.getRGB(0, y, width, 1, argb, 0, width);
      System.arraycopy(argb, 0, pixels, y * stride, width);
    }

    // Row sampling
    BitArray row = new BitArray(width);
    for (int y = 0; y < height; y++) {
      try {
        row = bitmap.getBlackRow(y, row);
      } catch (NotFoundException nfe) {
        // If fetching the row failed, draw a red line and keep going.
        int offset = y * stride + width;
        Arrays.fill(pixels, offset, offset + width, RED);
        continue;
      }

      int offset = y * stride + width;
      for (int x = 0; x < width; x++) {
        pixels[offset + x] = row.get(x) ? BLACK : WHITE;
      }
    }

    // 2D sampling
    try {
      for (int y = 0; y < height; y++) {
        BitMatrix matrix = bitmap.getBlackMatrix();
        int offset = y * stride + width * 2;
        for (int x = 0; x < width; x++) {
          pixels[offset + x] = matrix.get(x, y) ? BLACK : WHITE;
        }
      }
    } catch (NotFoundException ignored) {
      // continue
    }

    writeResultImage(stride, height, pixels, uri, ".mono.png");
  }
private static void dumpBlackPoint ( URI uri , BufferedImage image , BinaryBitmap bitmap ) throws IOException { int width = bitmap . getWidth ( ) ; int height = bitmap . getHeight ( ) ; int stride = width * 3 ; int [ ] pixels = new int [ stride * height ] ; int [ ] argb = new int [ width ] ; for ( int y = 0 ; y < height ; y ++ ) { image . getRGB ( 0 , y , width , 1 , argb , 0 , width ) ; System . arraycopy ( argb , 0 , pixels , y * stride , width ) ; } BitArray row = new BitArray ( width ) ; for ( int y = 0 ; y < height ; y ++ ) { try { row = bitmap . getBlackRow ( y , row ) ; } catch ( NotFoundException nfe ) { int offset = y * stride + width ; Arrays . fill ( pixels , offset , offset + width , RED ) ; continue ; } int offset = y * stride + width ; for ( int x = 0 ; x < width ; x ++ ) { pixels [ offset + x ] = row . get ( x ) ? BLACK : WHITE ; } } try { for ( int y = 0 ; y < height ; y ++ ) { BitMatrix matrix = bitmap . getBlackMatrix ( ) ; int offset = y * stride + width * 2 ; for ( int x = 0 ; x < width ; x ++ ) { pixels [ offset + x ] = matrix . get ( x , y ) ? BLACK : WHITE ; } } } catch ( NotFoundException ignored ) { } writeResultImage ( stride , height , pixels , uri , ".mono.png" ) ; }
Writes out a single PNG which is three times the width of the input image, containing from left
to right: the original image, the row sampling monochrome version, and the 2D sampling
monochrome version.