[java] drawing single pixels

Started by
5 comments, last by walkingcarcass 20 years ago
I''m using Java 2 1.4.2, my assignment involves calculating the colour of a pixel for a given (x,y) and drawing it. I''m given an off-screen Graphics interface, but I;ve checked the docs and other than drawing a line or rectangle of size 1, I can''t seem to find a way to say, basically: plotPixel(colour,x,y) am I being stupid
spraff.net: don't laugh, I'm still just starting...
Advertisement
You might want to check the java source code to see how they do it. Look under java.awt.Graphics.drawLine() and you might find what you want.... or not...

[edited by - garazdawi on April 13, 2004 12:44:09 PM]
garazdawi - 'I put the laughter back in slaughter'
Use a BufferedImage, and manipulate the buffer directly.
fillRect(x,y,1,1) will get the job done.
Anonymous Poster (1) is right. Use a BufferedImage, or a MemoryImageSource. You won''t find the source of java.awt.Graphics.drawLine(), and fillRect is too slow. Way too slow.
Why do my programs never work on other computers?
// create graphics context and imageGraphics graphics = getGraphics();BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);DataBufferInt data = (DataBufferInt)(image.getRaster().getDataBuffer());// get the framebufferint pixel[] = data.getData();// access individual pixels like thispixel[x+w*y] = 0xffffffff;// paint framebuffer on screengraphics.drawImage(image,0,0,w,h,null);
That worked great, thanks
spraff.net: don't laugh, I'm still just starting...

This topic is closed to new replies.

Advertisement