Create a BufferedImage Object:
BufferedImage bi = new new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
inside the drawing loop, set your pixels:
bi.setRGB(x, y, int_rgb);
...
and finally display the buffer image:
g.drawImage(bi, 0, 0, null);
If you discover setRGB () slowly, you can directly access the bitmap data:
int[] raster = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
and later
raster[y * 300 + x] = int_rgb;
astro source
share