public static BufferedImage renderBinary ( GrayU8 binaryImage , boolean invert , BufferedImage out ) { if ( out == null || ( out . getWidth ( ) != binaryImage . width || out . getHeight ( ) != binaryImage . height ) ) { out = new BufferedImage ( binaryImage . getWidth ( ) , binaryImage . getHeight ( ) , BufferedImage . TYPE_BYTE_GRAY ) ; } try { WritableRaster raster = out . getRaster ( ) ; DataBuffer buffer = raster . getDataBuffer ( ) ; if ( buffer . getDataType ( ) == DataBuffer . TYPE_BYTE ) { renderBinary ( binaryImage , invert , ( DataBufferByte ) buffer , raster ) ; } else if ( buffer . getDataType ( ) == DataBuffer . TYPE_INT ) { renderBinary ( binaryImage , invert , ( DataBufferInt ) buffer , raster ) ; } else { _renderBinary ( binaryImage , invert , out ) ; } } catch ( SecurityException e ) { _renderBinary ( binaryImage , invert , out ) ; } // hack so that it knows the buffer has been modified out . setRGB ( 0 , 0 , out . getRGB ( 0 , 0 ) ) ; return out ; }
Renders a binary image . 0 = black and 1 = white .