【发布时间】:2015-09-23 21:55:48
【问题描述】:
我有一个加载 .PNG 文件的图像,然后将它与我创建的其他图形结合起来。问题是我只需要旋转 .PNG 文件,而不是整个文件。想象一个速度计,你有一个从 0 到 200 的背景图像。该图像始终保持静止。现在,在它之上,你有一个指向你当前速度的箭头。那就是我要旋转的那个。
这是我目前所拥有的。它确实显示图形,但不旋转 .PNG(箭头)
Bitmap bitmap = new Bitmap(500, 280, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.White);
//this.Arrow = path to the .PNG
Image i = Image.FromFile(this.Arrow);
Bitmap a = new Bitmap(i.Width, i.Height);
Graphics ga = Graphics.FromImage(a);
a.SetResolution(ga.DpiX, ga.DpiY);
//It shouldn't rotate having the pivot at the (centre, centre)
//coordinates, but at the bottom of the image.
//The (21, 110) coordinates are right relative to the .PNG file
ga.TranslateTransform(21, 110);
ga.RotateTransform(45); //<--- Not rotating
ga.DrawImage(i, 0, 0);
g.DrawImage(i, new Rectangle(new Point(229, 120), new Size(i.Width, i.Height)));
g.DrawLine(new Pen(new SolidBrush(Color.Aquamarine), 1), 250, 0, 250, 280);
g.DrawLine(new Pen(new SolidBrush(Color.Aquamarine), 1), 0, 230, 500, 230);
有什么想法吗?
【问题讨论】:
-
您的问题可能与其他问题的第一个答案有关:stackoverflow.com/questions/27996037/…
-
它还没有工作。甚至尝试使用
Matrix()类和.Transform属性,但结果仍然相同。