Skip to content

how to draw a rotated image to context2d ? #1012

Answered by soywiz
rafi0 asked this question in Q&A
Discussion options

You must be logged in to vote

This works the same way that in JS Canvas Context2D.
When you are performing rotations and things like that, you can think like an imaginary axis that is transforming.
You can actually. Draw that axis. With something like:

stroke(2.0, Colors.RED) { line(0, 0, 10, 0); line(0, 0, 0, 10) }

You are rotating that axis, and you are saying to render that bitmap in the 0,0, which means that it will render at the 0,0 in the top left corner.
If you want a different behaviour, it is possible. If you want to render the image centered to that axis, you have to change the 0,0 coordinates into -width / 2, -height / 2.

bitmap.context2d {
  rotateDeg(rotation)
  drawImage(otherBitmap, -otherBitmap.width / 2

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by soywiz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1007 on September 29, 2022 15:05.