Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, im trying to work out how i can Rotate an image from the center of it. From what ive found out so far i need to use RotateTransform and TranslateTransform.

 

Ive tried all sorts of things to get this to work but so far no luck. :(

 

So just to sum up, i have an image which i need to spin around at an interval. (for example a circle with a smily face.. the outside of the circle would always be in the same place, just the :) would move around).

 

 

 

Thanks, Dan

  • *Experts*
Posted (edited)

You can use the RotateFlip method of the Bitmap object to rotate it:

Dim b As New Bitmap("some path")
'rotate the image by 90 degrees
b.RotateFlip(RotateFlipType.Rotate90FlipNone)

Edited by mutant
Posted

Ok ive had a look around the net and in the .net sdk and i found out that i need to create a matrix object, and use its rotateat method and then apply it to my graphics object.

 

       Dim fg As New Bitmap("C:\Images\Foreground.png")
       Dim g As Graphics = Me.CreateGraphics
       Dim TestMatrix As New Matrix
       Dim RotatePoint As New PointF(fg.Width / 2, fg.Height / 2)

       TestMatrix.RotateAt(90, RotatePoint)
       g.Transform = TestMatrix

       g.DrawImage(fg, 0, 0)

       g.Dispose()

 

I tried that and from what i can see it should be working? But my image is square and when i rotate it 90 degrees it doesnt end up where it began. Can anyone spot the problem?

 

 

 

Dan

Posted

Ok ive working it out :)

 

 

       Dim g As Graphics = Me.CreateGraphics
       Dim TestMatrix As New Matrix
       Dim RotatePoint As New PointF(fg.Width / 2, fg.Height / 2)

       TestMatrix.RotateAt(90, RotatePoint)
       g.Transform = TestMatrix

       g.DrawImage(fg, 0, 0, fg.Width, fg.Height)

       g.Dispose()

 

Apparently using DrawImage doesnt draw the image the right size unless you specify the width and height. I tried using DrawImageUnscaled but that had the same problem.

 

 

 

Dan :)

Posted

Just out of mindless curiosity could you use this approach to animate a sprite, thus using a single image as opposed to say 8?

 

Would this method involve too much overhead?

My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...