• Post Reply Bookmark Topic Watch Topic
  • New Topic

Quickest method to paint a single pixel in Graphics

 
Oleg Shubin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a lightweight graphics API for different needs where I want to render the image before it gets displayed. I have overriden the AWT's Component in order to have the highest perfomance. However, if I render the image (draw lines, rectangles & stuff) in the paint method the process of painting becomes visible to the user if the method is being called frequently (e.g. the window is being resized, or an animation is being played), and it is quite a perfomance-heavy solution.

I decided to cache and render the image separatly and simply copy the pixels to the Graphics object in the paint method. But now I don't know how to draw a single pixel to the Graphics object. I suppose the underlaying Sun implementation (sun.java2d.SunGraphics2D) has such method but I should not address that class. I know that Graphics class declares several methods (drawLine, drawRect, fillRect, etc.) that seem lightweight and can be used to only paint one pixel but I don't know which one will be the quickest.

I do not want to use BufferedImage due to some memory issues and thus drawImage is not a solution in this case.

tl;dr: the quickest method in java.awt.Graphics to set the color of some pixel by its coordinates to a specified color (java.awt.Color or RGB, last preferred).

Thank you in advance.

P.S. What frame rate should I expect if I have a java.awt.Frame with a single java.awt.Component that performs the said paint operations?
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a good reason for not wanting to use Swing, which superseded AWT about 15 years ago, and implements double buffering by default?
 
Oleg Shubin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Do you have a good reason for not wanting to use Swing, which superseded AWT about 15 years ago, and implements double buffering by default?

Yes, I do. I try to make my API as lightweight and fast as possible while Swing:
  • bases on AWT (additional processing);
  • has a lot of unnecessary utilities that are no use in my case but still require processing.

  • Additionally basing my API on more low-level library will allow using it in applications that do not use Swing at all.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!