Du kan gøre sådanne her:
// Prepare your pixel map: (Somewhere in your awt component...)
BufferedImage bufferedImage = (BufferedImage) Component.createImage (width, height);
// have your component make a buffered image.
// NOTE: requires Java 1.2, 1.3, or 1.4.
WritableRaster writeableRaster = (WritableRaster) bufferedImage.getRaster();
DataBufferInt dataBufferInt = (DataBufferInt)
writeableRaster.getDataBuffer()
// NOTE: Your Windows Desktop Graphics settings must be 32 bit RGB.
int [] pixelMap = dataBufferInt.getData();
// thats your *directly writable* pixel map!!!
// Yes, its *directly accessible*
// Now write what ever you want into the pixel map...
// Its offscreen, so no rips or tears happen...
// Each int is a argb type int.
Graphics offscreenGraphics = bufferedImage.getGraphics();
// AND you can also use g if you want to draw via the graphics methods.
// Now, setup the repaint method:
// Somewhere in your Canvas...
void throwPixelMapOntoScreen()
{ Graphics g = getGraphics();
g.drawImage (bufferedImage, 0, 0, width, height, null);
// there goes your pixelmap, onto the screen!
}
// also, setup the paint method:
void paint(Graphics g)
{ g.drawImage (bufferedImage, 0, 0, width, height, null);
}
-----------------------------------
Eller bruge g.drawLine() istedet med start og stop koordinaterne ens (hurtigere end at tegne firkanter)
Eller min egen favorit :
http://www.cfxweb.net/article.php?sid=169En fed beskrivelse om lige netop dit problem.