2013年11月17日星期日

Who has the experience to solve Canvas flashing ?

Most of you are not using Swing, but even still familiar AWT:

public class MyCanvas extends Canvas implements Observer, MouseListener

To solve the flicker problem , paint method is this:

public void paint (Graphics h)
{Rectangle r = getBounds ();
Image db = createImage (r.width, r.height);
Graphics g = db.getGraphics ();

/ / g to draw through
g.setColor (Color.green.darker (). darker ());
g.fillRect (0,0, r.width, r.height);

h.drawImage (db, 0,0, this);
}

there : public void update (Graphics g) {paint (g);}

even is such a program compiled , but sometimes there are still flashing
even only a last resort : the change in the update method repaint (x, y, width, height)
but this will increase the complexity of the program
even found the mouseClicked method in the code after the move mousePressed method
flashes decreased, but not completely eliminated

This is not a JVM problem ?





------ Solution ------------------------------------ --------
recommended double buffering technology . Go online to find .
------ Solution ---------------------------------------- ----
http://www.iteye.com/topic/624169
------ Solution -------------------- ------------------------
actually flashing again because the first painting background caused

g.setColor (Color.green.darker (). darker ());
g.fillRect (0,0, r.width, r.height);
so either directly on the use of image overwrite the contents of the last

or to only use double buffering , do not let the underpainting behavior displayed directly .
------ For reference only -------------------------------------- -
even google a bit , there are experts , said:
This method takes more resources , Image generally not more than 500X500
The duality Image is 640X480

It seems not lazy , Calcd redraw regions , using
repaint (x, y, width, height)
------ For reference only ------------------------ ---------------
special thanks icloud3!
even slowly research http://www.iteye.com/topic/624169
------ For reference only -------------- -------------------------


Sorry , even omit a lot of code
actual painting of the code far more than these
------ For reference only --------------------------- ------------

  
Sorry , even omit a lot of code   
actual painting of the code far more than these  

What I mean is , if the paint method in each first draw a background , there will be flashing effect .
tell you there is no other code omitted nothing .

so to speak, each frame in the animation is inserted before an entire screen of a single color , you think about what effect .

没有评论:

发表评论