/** * Creates a greyscale image from the given <code>{@link RasterDataNode}</code>. * <p/> * <p>The method uses the given raster data node's image information (an instance of <code>{@link * ImageInfo}</code>) to create the image. * * @param rasterDataNode the raster data node, must not be <code>null</code> * @param pm a monitor to inform the user about progress * * @return the color indexed image * * @throws IOException if the given raster data is not loaded and reload causes an I/O error * @see org.esa.beam.framework.datamodel.RasterDataNode#getImageInfo() */ public static BufferedImage createColorIndexedImage(final RasterDataNode rasterDataNode, ProgressMonitor pm) throws IOException { Guardian.assertNotNull("rasterDataNode", rasterDataNode); final int width = rasterDataNode.getSceneRasterWidth(); final int height = rasterDataNode.getSceneRasterHeight(); final ImageInfo imageInfo = rasterDataNode.getImageInfo(ProgressMonitor.NULL); final double newMin = imageInfo.getColorPaletteDef().getMinDisplaySample(); final double newMax = imageInfo.getColorPaletteDef().getMaxDisplaySample(); final byte[] colorIndexes = rasterDataNode.quantizeRasterData(newMin, newMax, 1.0, pm); final IndexColorModel cm = imageInfo.createIndexColorModel(rasterDataNode); final SampleModel sm = cm.createCompatibleSampleModel(width, height); final DataBuffer db = new DataBufferByte(colorIndexes, colorIndexes.length); final WritableRaster wr = WritableRaster.createWritableRaster(sm, db, null); return new BufferedImage(cm, wr, false, null); }