Jump to content
  • Advertisement
Sign in to follow this  
apprentice

[java] Drawing single pixels on the screen

This topic is 4811 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

How do you draw single pixels using Graphics2D? I am doing double buffering, and BufferStrategy only gives me access to a reference to a Graphics object (getDrawGraphics()). I think you can draw pixels on an image, but that's not what I want to do. I know that I could draw all the things I need on an image and then copy the whole image (instead of page-flipping), but wouldn't that be slow? Right now I am fine by using drawRect(x,y,1,1). I have no idea how fast/slow this method is.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure how to draw a single pixel to the screen besides using the geom class, but it seems that using a straight line to draw it would be quicker to process than using a rectangle because it seems like it would take more to calculate the four sides than just a single line. Even though you are using it for one pixel the method may still be calculating more than it needs to be. If this is the case Line2D.Float lineA = new Line2D.Float(x1,y1,x2,y2); should be quicker. This however may not be true and maybe someone else knows to just draw a single pixel.

-Jake

[Edited by - jake2431 on May 17, 2005 4:25:10 PM]

Share this post


Link to post
Share on other sites
You could use a BufferedImage, call the setRBG() method, and draw the image to the screen. This is a nice, simple way to change a single pixel in an image if one does not plan on changing pixels that often.

If you need to do a lot of pixel changing, use a BufferedImage and call the getRaster() method to receive a WritableRaster object that can be used to change the original image. WritableRaster has some handy methods over just a simple "setPixel".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!