[英]ArgumentException when using Graphics.DrawLines
我正在使用Visual Studio Express 2012。
我正在尝试绘制NRZI信号。 但是,每当我运行程序时,总会出现此错误:
System.Drawing.dll中发生了类型为'System.ArgumentException'的未处理异常。其他信息:参数无效。
错误出现在draws.DrawLines(Pens.Red, NRZI);
有人可以告诉我为什么吗?
这是我的代码:
Graphics draws;
Point[] NRZI = new Point[592]; // each binary value equals 74 pixels wide
string data = "10101010";
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int x = 0;
if (comboBox1.Text == "NRZI")
{
for (int c = 0; c < data.Length; c++)
{
if (data.ToCharArray()[c] == '0') // check if binary value is 0
{
for (int p = 0; p < 74; p++)
{
NRZI[x] = new Point(x, 109); // point to signify 0 or low
x++;
}
}
if (data.ToCharArray()[c] == '1') // check if binary value is 1
{
for (int p = 0; p < 74; p++)
{
NRZI[x] = new Point(x, 9); // point to signify 1 or high
x++;
}
}
}
this.Refresh(); // calls paint
for (w = 0; w < pictureBox1.Width; w++)
{
draws.DrawLines(Pens.Red, NRZI);
}
}
}
看起来您使用了错误的Graphics
对象。 在paint事件处理程序中,您需要使用提供的PaintEventArgs e
参数的PaintEventArgs.Graphics
属性:
e.Graphics.DrawLines(Pens.Red, NRZI);
我刚才有同样的问题。 问题是图形对象被处置了 。 因此,它的每个属性和方法都会引发此异常。 如果有人迷路了,我会给出这个答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.