dannyres Posted November 22, 2003 Posted November 22, 2003 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 Quote
*Experts* mutant Posted November 22, 2003 *Experts* Posted November 22, 2003 (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 November 22, 2003 by mutant Quote
dannyres Posted November 22, 2003 Author Posted November 22, 2003 Yeah that works fine for angles like 90, 180, but what if I want to rotate 33 degrees? Dan Quote
*Experts* mutant Posted November 22, 2003 *Experts* Posted November 22, 2003 Look into the Transform property of the Graphics object. Using it you can manipulate rotating by 2d matrices. Quote
dannyres Posted November 22, 2003 Author Posted November 22, 2003 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 Quote
dannyres Posted November 22, 2003 Author Posted November 22, 2003 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 :) Quote
hog Posted November 25, 2003 Posted November 25, 2003 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? Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.