int sizeX = displayImage.getWidth(); int sizeY = displayImage.getHeight(); DataBufferByte buffer = new DataBufferByte(sizeX*sizeY, 3); DataBuffer dataBuf = displayImage.getRaster().getDataBuffer(); ColorModel cm = displayImage.getColorModel(); int v; for (int y = 0; y < sizeY; ++y) { for (int x = 0; x < sizeX; ++x) { v = dataBuf.getElem(0, sizeX*y+x); buffer.setElem(0, sizeX*y+x, cm.getRed(v)); buffer.setElem(1, sizeX*y+x, cm.getGreen(v)); buffer.setElem(2, sizeX*y+x, cm.getBlue(v)); } } ComponentColorModel ccm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), null, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); BandedSampleModel csm = new BandedSampleModel(DataBuffer.TYPE_BYTE, sizeX, sizeY, 3); return new BufferedImage(ccm, Raster.createWritableRaster(csm, buffer, null), false, null);
if (displayImage == null) return null; return ImageFactory.getImage(displayImage);
    public BufferedImage getDisplayImage()    {         //Now we only need to tell Java2D how to handle the RGB buffer.         int sizeX = displayImage.getWidth();        int sizeY = displayImage.getHeight();        DataBufferByte buffer = new DataBufferByte(sizeX*sizeY, 3);        DataBuffer dataBuf = displayImage.getRaster().getDataBuffer();        ColorModel cm = displayImage.getColorModel();        int v;        for (int y = 0; y < sizeY; ++y) {            for (int x = 0; x < sizeX; ++x) {                v = dataBuf.getElem(0, sizeX*y+x);                buffer.setElem(0, sizeX*y+x, cm.getRed(v));                buffer.setElem(1, sizeX*y+x, cm.getGreen(v));                buffer.setElem(2, sizeX*y+x, cm.getBlue(v));            }         }          ComponentColorModel ccm = new ComponentColorModel(                                    ColorSpace.getInstance(ColorSpace.CS_sRGB),                                     null, false, false, Transparency.OPAQUE,                                     DataBuffer.TYPE_BYTE);        BandedSampleModel csm = new BandedSampleModel(DataBuffer.TYPE_BYTE,                                     sizeX, sizeY, 3);        return new BufferedImage(ccm,                 Raster.createWritableRaster(csm, buffer, null), false, null);    }