ImageUtils { public static RenderedImage createRenderedImage(int width, int height, ProductData data) { final int dataBufferType = ImageManager.getDataBufferType(data.getType()); DataBuffer db; if (dataBufferType == DataBuffer.TYPE_BYTE) { db = new DataBufferByte((byte[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_USHORT) { db = new DataBufferUShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_SHORT) { db = new DataBufferShort((short[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_INT) { db = new DataBufferInt((int[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_FLOAT) { db = new DataBufferFloat((float[]) data.getElems(), data.getNumElems()); } else if (dataBufferType == DataBuffer.TYPE_DOUBLE) { db = new DataBufferDouble((double[]) data.getElems(), data.getNumElems()); } else { throw new IllegalStateException("illegal image data buffer type: " + dataBufferType); } SampleModel sampleModel = createSingleBandedSampleModel(dataBufferType, width, height); final ColorModel colorModel = PlanarImage.createColorModel(sampleModel); final WritableRaster raster = WritableRaster.createWritableRaster(sampleModel, db, new Point(0, 0)); return new MyRenderedImage(raster, colorModel); }  static BufferedImage convertImage(RenderedImage image, int imageType); static double[] getDataTypeMinMax(int dataType, double[] minmax); static String getDataTypeName(int dataType); static String getColorSpaceName(int spaceType); static BufferedImage createGreyscaleColorModelImage(int width, int height, byte[] data); static BufferedImage createIndexedImage(int width, int height, byte[] data, IndexColorModel cm); static ColorModel create8BitGreyscaleColorModel(); static Object getPrimitiveArray(DataBuffer dataBuffer); static Object createDataBufferArray(int dataBufferType, int size); static SampleModel createSingleBandedSampleModel(int dataBufferType, int width, int height); static RenderedImage createRenderedImage(int width, int height, ProductData data);  }
@Test public void testCreateRenderedImage() { testByte(); testUShort(); testShort(); testInt(); testFloat(); testDouble(); }