我需要将汽车图像旋转 X 度以指示行驶方向。现在我有这个工作代码可以在 GDI+ 表面上绘制图像。
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);
Run Code Online (Sandbox Code Playgroud)
如何旋转X度?
以下是旋转图像的方法
//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);
Run Code Online (Sandbox Code Playgroud)