Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - drawing many images with Graphics.drawImage() and 2-screen buffer strategy distorts and cuts images
    text
    copied!<p>I am using a loop to invoke double buffering painting. This, together with overriding my only Panel's repaint method, is designed to pass complete control of repaint to my loop and only render when it necessary (i.e. some change was made in the GUI).</p> <p>This is my rendering routine:</p> <pre><code> Log.write("renderer painting"); setNeedsRendering(false); Graphics g = frame.getBufferStrategy().getDrawGraphics(); g.setFont(font); g.setColor(Color.BLACK); g.fillRect(0, 0, window.getWidth(),window.getHeight()); if(frame != null) window.paint(g); g.dispose(); frame.getBufferStrategy().show(); </code></pre> <p>As you can see, it is pretty standard. I get the grpahics object from the buffer strategy (initialized to 2), make it all black and pass it to the paint method of my "window" object.</p> <p>After window is done using the graphics object, I dispose of it and invoke show on the buffer strategy to display the contents of the virtual buffer.</p> <p>It is important to note that window passes the graphics object to many other children components the populate the window and each one, in turn, uses the same instance of the graphics object to draw something onto the screen: text, shapes, or images.</p> <p>My problem begins to show when the system is running and a large image is rendered. The image appears to be cut into seveeal pieces and drawn again and again (3-4 times) with different offsets inside of where the image is supposed to be rendered. See my attached images:</p> <p>This is the original image: <a href="http://img109.imageshack.us/img109/8308/controller.png" rel="nofollow noreferrer">alt text http://img109.imageshack.us/img109/8308/controller.png</a></p> <p>This is what I get: <a href="http://img258.imageshack.us/img258/3248/probv.png" rel="nofollow noreferrer">alt text http://img258.imageshack.us/img258/3248/probv.png</a></p> <p>Note that in the second picture, I am rendering shapes over the picture - these are always at the correct position.</p> <p>Any idea why this is happening? If I save the image to file, as it is in memory, right before the call to g.drawImage(...) it is identical to the original.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload