0
votes

I am stuck with the following problem:

I have an android Bitmap and a set of 4 coordinates, representing a rectangle. However, the rectangle may be rotated. For example I may have the coordinates 0/50, 50/0, 100/50, 50/100. Therefore I cannot simply use the Canvas drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) function because I cannot specify such coordinates in a rect Object. What would be the best way to extract such a rectangle?

1
Have a look at the Lunar lander sample code that comes with the SDK. In LunarView.java search for 'rotate'. That will show you how they spin the drawing of the spaceship.NickT

1 Answers

1
votes

Can you calculate what angle your rectangle is tilted? In that case you can rotate the canvas:

canvas.rotate(angle, px, py);

where px and py are the coordinates for the center of the rectangle.

And then do the drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint).