I need to rotate my image of a car X degrees to indicate the direction of travel. Right now I have this working code to draw the image on a GDI+ surface.
int hdc = Display.hDC;
IntPtr p = new IntPtr(hdc);
graphics = Graphics.FromHdc(p);
newImage = Image.FromFile(carImage);
System.Drawing.Point ulCorner = new System.Drawing.Point(x - 25, y -15);
//graphics.RotateTransform(45); //tried this line, when i used it, it drew nothing.
graphics.DrawImage(newImage, ulCorner);
how to rotate X degrees?
Here's how to rotate an image
//move rotation point to center of image
graphics.TranslateTransform((float)newImage.Width/2,(float)newImage.Height / 2);
//rotate
graphics.RotateTransform(angle);
//move image back
graphics.TranslateTransform(-(float)newImage.Width/2,-(float)newImage.Height / 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With