Dear Pinko: (sorry, I just always wanted to say that)There are probably better ways, and maybe I don't undestand what you want to do, but you can use PixelGrabber to load an image into an array of size height * width and then set the RGB and alpha for an individual pixel. Its covered pretty good in the AWT tutorial.
Hey Hey Hey! Howto draw pixels EASILY? Here it is!
// 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);
}
--
You know what? It took me 5 months to put these 5 pieces of information together. Un-be-*#!^-ing-be-liev-able !
WHY does JAVA documentation tell you how to do everything *BUT* the most basic operation of putting pixels on the screen?
Tell me if you know. PLEASE.
ahem... g.drawLine(x,y,x,y) where g is an instance of java.awt.Graphics sets the pixel at (x,y) to the foreground color. (It should also be faster than filling a rectangle with width=height=0 according to some resources but I can't be sure)
If you really need to go to the pixel level (image processing with java version < 1.2 or coding demo applets?) see http://www.cfxweb.net/article.php?sid=169