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 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. It is also not the case asked in this question because, again, I do not use Images and I do not create new instances in the paint
method (the rendered image data class only changes when the component is resized).
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.