Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

walkingcarcass

[java] drawing single pixels

This topic is 5242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use a BufferedImage, and manipulate the buffer directly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
fillRect(x,y,1,1) will get the job done.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

// create graphics context and image

Graphics graphics = getGraphics();
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
DataBufferInt data = (DataBufferInt)(image.getRaster().getDataBuffer());
// get the framebuffer

int pixel[] = data.getData();

// access individual pixels like this

pixel[x+w*y] = 0xffffffff;
// paint framebuffer on screen

graphics.drawImage(image,0,0,w,h,null);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!