本文介绍了Graphics和PathGradientBrush转换错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
e.Graphics.RotateTransform(30)之后的下一个代码出错了;
The next code goes wrong after e.Graphics.RotateTransform(30);
public Form1()
{
InitializeComponent();
this.BackColor = Color.Black;
this.DoubleBuffered = true;
this.Paint += Draw;
this.Invalidate();
}
private void Draw(object sender, System.Windows.Forms.PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new Rectangle(50, 50, 100, 20));
using (PathGradientBrush pgb = new PathGradientBrush(path))
{
pgb.FocusScales = new PointF(1f, 0f);
pgb.CenterColor = Color.FromArgb(255, 255, 255, 255);
pgb.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
e.Graphics.RotateTransform(30); // Error!
e.Graphics.FillRectangle(pgb, 0, 0, 200, 200);
}
}
右:
没有e.Graphics.RotateTransform(30);
[]
错误:
使用e.Graphics.RotateTransform(30);
[ ]
如何修复?
我想我也应该改造PathGradientBrush。
Right:
Without e.Graphics.RotateTransform(30);
https://social.msdn.microsoft.com/Forums/getfile/542870[^]
Wrong:
With e.Graphics.RotateTransform(30);
https://social.msdn.microsoft.com/Forums/getfile/542871[^]
How to fix?
I think i should also transform PathGradientBrush.
推荐答案
private void Draw(object sender, System.Windows.Forms.PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new Rectangle(50, 50, 100, 20));
using (PathGradientBrush pgb = new PathGradientBrush(path))
{
pgb.FocusScales = new PointF(1f, 0f);
pgb.CenterColor = Color.FromArgb(255, 255, 255, 255);
pgb.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
e.Graphics.RotateTransform(30); // error!
e.Graphics.FillPath(pgb, path);
//e.Graphics.FillRectangle(pgb, 0, 0, 200, 200);
}
}
这篇关于Graphics和PathGradientBrush转换错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!