问题描述
- C#GDI+画折线时候出现大红叉
-
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{ //定义坐标数组
double[,] yt = new double[60, 2]{ { 1.0000000e+00, 9.9939635e-01},
{ 2.0000000e+00 , 9.9945106e-01},
{ 3.0000000e+00 , 1.0019092e+00},
{ 4.0000000e+00 , 9.9956401e-01},
{ 5.0000000e+00 , 9.9969424e-01},
{ 6.0000000e+00 , 1.0019383e+00},
{ 7.0000000e+00 , 1.0008281e+00},
{ 8.0000000e+00 , 9.9989639e-01},
{ 9.0000000e+00 , 1.0000202e+00},
{ 1.0000000e+01 , 1.0001368e+00},
{ 1.1000000e+01 , 1.0012033e+00},
{ 1.2000000e+01 , 1.0003697e+00},
{ 1.3000000e+01 , 1.0004423e+00},
{ 1.4000000e+01 , 1.0000165e+00},
{ 1.5000000e+01 , 1.0002151e+00},
{ 1.6000000e+01 , 1.0008204e+00},
{ 1.7000000e+01 , 1.0000468e+00},
{ 1.8000000e+01 , 1.0009050e+00},
{ 1.9000000e+01 , 1.0005483e+00},
{ 2.0000000e+01 , 1.0013960e+00},
{ 2.1000000e+01 , 1.0002895e+00},
{ 2.2000000e+01 , 1.0004147e+00},
{ 2.3000000e+01 , 1.0012323e+00},
{ 2.4000000e+01 , 1.0018748e+00},
{ 2.5000000e+01 , 1.0006120e+00},
{ 2.6000000e+01 , 1.0010838e+00},
{ 2.7000000e+01 , 1.0011010e+00},
{ 2.8000000e+01 , 9.9965701e-01},
{ 2.9000000e+01 , 1.0007636e+00},
{ 3.0000000e+01 , 9.9904094e-01},
{3.1000000e+01 , 1.0012401e+00},
{3.2000000e+01 , 9.9855141e-01},
{3.3000000e+01 , 9.9893610e-01},
{3.4000000e+01 , 9.9815102e-01},
{ 3.5000000e+01 , 9.9806811e-01},
{ 3.6000000e+01 , 1.0028732e+00},
{ 3.7000000e+01 , 1.0017001e+00},
{ 3.8000000e+01 , 9.9865784e-01},
{ 3.9000000e+01 , 1.0049378e+00},
{ 4.0000000e+01 , 9.9677380e-01},
{ 4.1000000e+01 , 9.9942097e-01},
{ 4.2000000e+01 , 9.9885276e-01},
{4.3000000e+01 , 1.0032138e+00},
{4.4000000e+01 , 1.0037719e+00},
{4.5000000e+01 , 9.9677094e-01},
{4.6000000e+01 , 9.9987356e-01},
{4.7000000e+01 , 9.9930986e-01},
{4.8000000e+01 , 1.0020807e+00},
{4.9000000e+01 , 1.0031585e+00},
{5.0000000e+01 , 1.0040415e+00},
{5.1000000e+01 , 9.9684219e-01},
{5.2000000e+01 , 1.0029911e+00},
{5.3000000e+01 , 1.0026526e+00},
{5.4000000e+01 , 9.9484267e-01},
{5.5000000e+01 , 9.9403223e-01},
{5.6000000e+01 , 9.9997038e-01},
{5.7000000e+01 , 1.0096125e+00},
{5.8000000e+01 , 9.9704078e-01},
{5.9000000e+01 , 1.0017329e+00},
{6.0000000e+01 , 9.9469950e-01},};
//定义个用来储存转换类型的坐标数组
float[,] tg = new float[60, 2];
//转换数组类型
for (int i = 0; i <= yt.Length; i++)
{
for (int j = 0; j <= 1; j++)
{
tg[i, j] = (float)yt[i, j];}; }; //画布 Bitmap bmap = new Bitmap(800, 400); Graphics gph = Graphics.FromImage(bmap); gph.Clear(Color.White);//画布颜色 PointF cpt = new PointF(50, 200);//原点 PointF[] xpt = new PointF[3]{new PointF(665,200), new PointF(650,208), new PointF(650,192) }; //用来绘制箭头 Pen mypen = new Pen(Color.Black, 1);//绘制坐标直线的笔 gph.DrawPolygon(mypen, xpt);//画箭头 gph.FillPolygon(new SolidBrush(Color.Black), xpt);//填充箭头颜色 //绘制坐标线条 gph.DrawLine(mypen, cpt.X, cpt.Y, 650, 200); gph.DrawLine(mypen, cpt.X, 0, 50, 200); gph.DrawLine(mypen, cpt.X, cpt.Y, 50, 400); //绘制图像 Pen ytpen= new Pen(Color.Blue,1); for (int t=0;t<=yt.Length-1 ;t++ ) { PointF A=new PointF(tg[t,0],tg[t,1]); PointF B=new PointF(tg[t+1,0],tg[t+1,1]); gph.DrawLine(ytpen,A,B); }; //在piturebox插件上显示 pictureBox1.Image = bmap; }
解决方案
没代码,只能给你几个链接了。
http://www.cnblogs.com/shengtianlong/archive/2010/06/12/1756989.html
http://www.cnblogs.com/peterzb/archive/2009/07/19/1526555.html
解决方案二:
只要你的paint代码丢出了异常,都是大红叉。所以具体还是请你自己调试下。
解决方案三:
说明绘制过程出错,可能有空对象,可能计算出错,比如除零,下个断点调试一下吧
时间: 2024-11-16 02:18:03