Skip to content Skip to sidebar Skip to footer

Android: How To Draw A Rectangle On A Movable Image Such That The Drawn Rectangle Also Moves Along With The Image?

I have an image which is movable throughout the screen. Now, I want to draw a rectangle on this image such that when I move the image the rectangle drawn on the image also moves. C

Solution 1:

Well I figured my own way. It was just a small change in the above code which was necessary. It is enough to define the co-ordinates of rectangle with respect to x and y obtained due to touch events. for example, you can do the following:

myRectangle.set(x-50, y-50, x+50, y+50);

And the rest will be taken care automatically.

Solution 2:

In onCreate, create a new Bitmap image and a canvas for that bitmap. Use that canvas to draw the original bitmap and a rectangle to the new bitmap. Then in onDraw just draw that new bitmap wherever you want to. As a bonus you'll have very fast onDraws.

Post a Comment for "Android: How To Draw A Rectangle On A Movable Image Such That The Drawn Rectangle Also Moves Along With The Image?"