Not sure if this will help, but here's code for accessing pixel[] arrays in a BufferedImage quickly, so you don't have to copy from a MemoryImageSource.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| int w = getWidth(); int h = getHeight(); int[] pixels = new int[w * h]; DirectColorModel colorModel = new DirectColorModel(24, 0xff0000, 0x00ff00, 0x0000ff);
SampleModel sampleModel = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, w, h, new int[] { 0xff0000, 0x00ff00, 0x0000ff }); DataBuffer dataBuffer = new DataBufferInt(pixels, w * h); WritableRaster raster = Raster.createWritableRaster( sampleModel, dataBuffer, new Point(0,0)); awtImage = new BufferedImage(colorModel, raster, true, new Hashtable()); |
And does that end up being quicker than using the WritableRaster that is supplied by the BufferedImage automatically? I tried
1
| int[] pixels = ((DataBufferInt)memImage.getRaster().getDataBuffer()).getData(0); |
and it ends up being much slower than the version I have now