drawing pixels

Is there anyway to just draw a pixel at a specified point?I need to do that but I looked in the "Graphics" class and couldn't find anything, if you know of anything then plz say so.
[203 byte] By [CaptainPinko] at [2007-9-26 2:50:36]
# 1
I couldn't find anything either, so I made do with drawRect(x, y, 0, 0)
shirish_wagh at 2007-6-29 10:37:16 > top of Java-index,Archived Forums,Java Programming...
# 2

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.

Stemco at 2007-6-29 10:37:16 > top of Java-index,Archived Forums,Java Programming...
# 3

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.

getcha at 2007-6-29 10:37:16 > top of Java-index,Archived Forums,Java Programming...
# 4
It's all there if you know where to look, and also I'm pretty pleased that there's no Putpixel in java, since I fail to see the interest in putting a single pixel on screen.
Kayaman at 2007-6-29 10:37:16 > top of Java-index,Archived Forums,Java Programming...
# 5

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

jsalonen at 2007-6-29 10:37:16 > top of Java-index,Archived Forums,Java Programming...