其他分享
首页 > 其他分享> > CodeGo.net>如何旋转System.Drawing.Image X度?

CodeGo.net>如何旋转System.Drawing.Image X度?

作者:互联网

我需要将汽车图像旋转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);

如何旋转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);

标签:gdi-2,c
来源: https://codeday.me/bug/20191102/1990210.html