public static BufferedImage toBufferedImage(BitMatrix matrix, MatrixToImageConfig config) {
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    BufferedImage image = new BufferedImage(width, height, config.getBufferedImageColorModel());
    int onColor = config.getPixelOnColor();
    int offColor = config.getPixelOffColor();
    int[] rowPixels = new int[width];
    BitArray row = new BitArray(width);
    for (int y = 0; y < height; y++) {
      row = matrix.getRow(y, row);
      for (int x = 0; x < width; x++) {
        rowPixels[x] = row.get(x) ? onColor : offColor;
      }
      image.setRGB(0, y, width, 1, rowPixels, 0, width);
    }
    return image;
  }
public static BufferedImage toBufferedImage ( BitMatrix matrix , MatrixToImageConfig config ) { int width = matrix . getWidth ( ) ; int height = matrix . getHeight ( ) ; BufferedImage image = new BufferedImage ( width , height , config . getBufferedImageColorModel ( ) ) ; int onColor = config . getPixelOnColor ( ) ; int offColor = config . getPixelOffColor ( ) ; int [ ] rowPixels = new int [ width ] ; BitArray row = new BitArray ( width ) ; for ( int y = 0 ; y < height ; y ++ ) { row = matrix . getRow ( y , row ) ; for ( int x = 0 ; x < width ; x ++ ) { rowPixels [ x ] = row . get ( x ) ? onColor : offColor ; } image . setRGB ( 0 , y , width , 1 , rowPixels , 0 , width ) ; } return image ; }
As {@link #toBufferedImage(BitMatrix)}, but allows customization of the output.

@param matrix {@link BitMatrix} to write
@param config output configuration
@return {@link BufferedImage} representation of the input