Succinct example of rotating a canvas 90 degrees

jima

Member
Licensed User
Longtime User
NEEDED: Succinct example of rotating a canvas 90 degrees

New User. I need an uncluttered example of rotating (the current contents of) a canvas 90 degrees. I am doing this in a panel which dynamically flips height and width - that part works! I *know* this should be fairly easy to do - for someone 1% smarter than me! Thanks in advance.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code rotates the existing drawings:
B4X:
Sub Button1_Click
   Dim b As Bitmap
   b.Initialize3(cvs.Bitmap)
   Dim r As Rect
   r.Initialize(0, 0, cvs.Bitmap.Width, cvs.Bitmap.Height)
   cvs.DrawBitmapRotated(b, Null, r, 90)
   Panel1.Invalidate
End Sub

See the attached project (click on the panel to draw on it).
 

Attachments

  • 1.zip
    6.6 KB · Views: 346
Upvote 0

jima

Member
Licensed User
Longtime User
excellent, thank you. but...

Is it a requirement that the width and height be =? For oblong canvas results are not appealing. It appears that rotate works only with the center as a pivot point and on a canvas that is a square. Please correct this if wrong. Also, I assume this is a limitation of the underlying android framework and not something "correctable" within b4a.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Is it a requirement that the width and height be =?
No. Have a look at chapter 16.2.1 Drawing rotating bitmaps in the Beginner's Guide.

It appears that rotate works only with the center as a pivot point...
Yes.

... and on a canvas that is a square.
No, you can draw the rotated bitmap wherever you want. But the pivot point is the mid point of the rectangular bitmap. You can play with transparent parts in the bitmap to 'move' the pivot.

Also, I assume this is a limitation of the underlying android framework and not something "correctable" within b4a.
I think so.

Best regards.
 
Upvote 0

jima

Member
Licensed User
Longtime User
Thanks Klaus and Erel

The phenomenon I'm getting is stretching/distortion when using oblong canvases. I've resolved by another method but expect to revisit this someday.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…