Sign in to follow this  

[java] Drawing single pixels on the screen

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

This topic is 4593 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this