Skip to content Skip to sidebar Skip to footer

Redraw Image On Canvas On Touch Event?

I am trying to redraw an image on the canvas on an onTouch event. I am able to draw the image on the canvas, but I want the image to redraw at a particular x,y. protected void onDr

Solution 1:

I think I understand your problem. You are calling postinvalidate() method each time when action.down is called, so it calls ultimately call ondraw(). So it will redraw it on bitmap for particular setted value at which you put in ondraw again.

So you looks that it remain unchanged.

Follow these steps:

  1. use some public variables for drawing bitmaps in ondraw method for x and y axis, lets say initx and inity

  2. then on touch event:update this value by adding your x and y value to initx and inity resp.

    like:initx=initx+x;
    inity=inity+y;
    

And last in cation down event just call post.invalidate or ondraw method.

Solution 2:

See the MotionEvent class that provides the coordinates of where the user touched the screen.

Post a Comment for "Redraw Image On Canvas On Touch Event?"