===============GDI+======================

zl194 zl194 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面的代码是我写的一个类似于股票图的代码,大意是在一个底稿上画2条曲线,一个标准值,一个检测值,并画出x和y的坐标轴刻度和图例。

方法可以正常运行,也能得到图像,在win2003的机器上,总是在程序运行很久以后(如这个方法运行结束了几分钟后)提示GDI+错误,在Winxp上就很少有提示,至少我测试的机器上没出过。

public static Bitmap writeImage(Bitmap image,double[] dubleY1, double[] DubleY2, int[] xLine1,int[] xLine2, double yStart, double yUnit, int xUnit, string yName,int tt,int xStart)
{
Pen p1 = Pens.Blue; //写图例的画笔
Pen p2 = Pens.Red;
Brush bs1 = Brushes.Blue; //画线用的
Brush bs2 = Brushes.Red;
int[] y1 = getYpoint1(dubleY1, yStart, yUnit); //Y轴的坐标点
int[] y2 = getYpoint1(DubleY2, yStart, yUnit); //Y轴的坐标点

//Bitmap image = Resource2.KT3;//线图底稿

Bitmap newimage = new Bitmap(image.Width, image.Height);
Graphics oGraphic = Graphics.FromImage(newimage);
Point p00 = new Point(0, 0);
oGraphic.DrawImage(image, p00);
image.Dispose();
image = newimage;


Point[] py1 = new Point[y1.Length];
Point[] py2 = new Point[y2.Length];

……这里有一段得到Y 点数组的代码,取得每个Y点的位置

using (Graphics g = Graphics.FromImage(image)) //在背景图上画 折线图
{
if (py1.Length > 1)
{
g.DrawLines(p1, py1);//标准值 曲线
}
if (py2.Length > 1)
{
g.DrawLines(p2, py2);//检测值 曲线
}

//画y轴坐标
for (int i = 0; i <7; i++)
{
double iYvalue = yStart + yUnit * 20 * i;
g.DrawString(iYvalue.ToString("0.00"), ft, bs2, theYs[i]);

}
//画x轴坐标
for (int i = 0; i <5; i++)
{
string xValue = "0";

int theXvalue = (i * xUnit + 1) * 50;
xValue = Convert.ToInt32(i * 5 * xUnit+xStart).ToString();


g.DrawString(xValue, ft, Brushes.White, theXs[i]);
}
//画出图例
int leng = yName.Length;
Point pA;
Point pB;
switch (tt)
{
case 0:
pA = new Point(700, 20);
pB = new Point(700, 35);
^ default:
pA = new Point(1820, 1160);
pB = new Point(1820, 1175);
break;
}

g.DrawString("[" + yName + ":标准值]", ft2, bs1, pA);
g.DrawString("[" + yName + ":检测值]", ft2, bs2, pB);


}
return image;


}


谁能帮我分析分析是怎么回事呢,或者这种不是实时出现的错误怎么测试呢。
...全文
评论 33
收藏 已收藏
分享
返回顶部
zl194
C# 111,129 成员 642,538 内容