Like the memory leak that mtraut and Hamza Erlikaya pointed out, you are also an unnecessary copy of the pixel data ( MemoryImageSource wraps the array, but then Image allocates its own buffer and copies the original pixels into it.)
You can avoid this by creating a BufferedImage that partitions the array:
ColorModel cm = ColorModel.getRGBdefault(); DataBuffer buffer = new DataBufferInt(pxs, width * height); WritableRaster raster = Raster.createPackedRaster(buffer, width, height, width, new int[] {0xFF0000, 0xFF00, 0xFF, 0xFF000000}, null); BufferedImage img = new BufferedImage(cm, raster, false, null);
finnw source share