[java] drawing single pixels
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
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]
[edited by - garazdawi on April 13, 2004 12:44:09 PM]
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.
// 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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement