java - Refresh BufferedImage -


i wanted create simple paint brush in jframe. it, have created bufferedimage , when mouse dragged, i've redrawn set image changes.

the problem if drag mouse fast not points drawn. looks dotted line.

and here code update image:

public void mousedragged(mouseevent evt)  {        int x = evt.getx();     int y = evt.gety();      if(eraser == false)            this.dice(x, y);     else         this.eraser(x, y);      g = (graphics2d) this.getgraphics();     g.drawimage(image, positionx, positiony, null);     g.dispose(); } 

in dice , eraser methods make changes image (i set pixels). don't know how repair it.

thanks help.

i think due swing "buffering" mousedragged-event (i.e. if mouse moved more 1 pixel per interrupt, called once). try storing latest reported mouse position, , instead of calling this.dice()/this.eraser() once pixel, call in between starting(last) position, , position of current mouse event.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -