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

zl194 2009-12-28 03:31:12
下面的代码是我写的一个类似于股票图的代码,大意是在一个底稿上画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;


}


谁能帮我分析分析是怎么回事呢,或者这种不是实时出现的错误怎么测试呢。
...全文
392 33 打赏 收藏 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
LorenLiu 2009-12-31
  • 打赏
  • 举报
回复
把image.Dispose();
image = newimage;
去掉,然后后面的image的地方都改用newimage试试

不太明白为什么要dispose掉image,然后把newimage赋给image再对image操作。。。
wo6522317 2009-12-31
  • 打赏
  • 举报
回复
这个 image 对象返回后有保存操作吗?
lovelan1748 2009-12-31
  • 打赏
  • 举报
回复
帮顶
qiqundelang 2009-12-31
  • 打赏
  • 举报
回复
可以!
huipengzheng@sina.com
zl194 2009-12-31
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 qiqundelang 的回复:]
要是愿意代码发给我
我给你调!
[/Quote]

谢谢!光给你一个图像类行吗,别的部分我不能做主,如过你有win2003的环境就帮我测测。
zl194 2009-12-31
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 yuxuanji 的回复:]
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();


这段代码的逻辑混乱,究竟是要干什么?
你可以用一个 Rectangle
再用Graphics.DrawPie
[/Quote]

这段是有些问题,原想是释放掉image,在新的图像里操作,避免原图像的锁定。现在改了,将image = newimage;去掉了,后面的引用全部使用newimage,并返回newimage.但还是不行。
zl194 2009-12-31
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 lorenliu 的回复:]
把image.Dispose();
  image = newimage;
去掉,然后后面的image的地方都改用newimage试试

不太明白为什么要dispose掉image,然后把newimage赋给image再对image操作。。。
[/Quote]

这段我也检查有问题,现在把 image=newimage;去掉了,直接使用newimage,最后返回newimage.
但还是有同样的错误。我现在开始感觉是win2003的问题了。愁!!
qiqundelang 2009-12-31
  • 打赏
  • 举报
回复
要是愿意代码发给我
我给你调!
LutzMark 2009-12-31
  • 打赏
  • 举报
回复
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;

这段代码的逻辑混乱,究竟是要干什么?
你可以用一个 Rectangle
再用Graphics.DrawPie
zl194 2009-12-30
  • 打赏
  • 举报
回复
还是不行啊。有没有什么方法能测试出到底是什么位置出的错误。每次错误都是在没有任何操作的情况下弹出的。
wzuomin 2009-12-28
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 wuyq11 的回复:]
使用了相同的文件名称,或者上次的对象没有Dispose掉 
解决A generic error occurred in GDI+
[/Quote]

帮顶
wuyq11 2009-12-28
  • 打赏
  • 举报
回复
使用了相同的文件名称,或者上次的对象没有Dispose掉
解决A generic error occurred in GDI+
特别 2009-12-28
  • 打赏
  • 举报
回复
没有server的OS
不好测
tianliang1 2009-12-28
  • 打赏
  • 举报
回复
gdi+ 后生来看哈。。。帮顶。。。
fut20090715 2009-12-28
  • 打赏
  • 举报
回复
会不会跟垃圾回收有关
因为server和workstation的机制不一样
ourola 2009-12-28
  • 打赏
  • 举报
回复
GDI+ 的一般性错误. 你去查查资料就知道了..
adrianEvin 2009-12-28
  • 打赏
  • 举报
回复
定下
zl194 2009-12-28
  • 打赏
  • 举报
回复
等待中
zl194 2009-12-28
  • 打赏
  • 举报
回复
错误是:
对话框标题:Microsoft .NET Framework
内容:
Unhandled exception has occured in your application If
you click Continue,the application will ignore this
error and attemp to contion.If you click Quit,
the application will close immediately

A generic error occurred in GDI+

详细:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.Graphics.Clear(Color color)
at System.Windows.Forms.ToolStripSystemRenderer.RenderStatusStripBackground(ToolStripRenderEventArgs e)
at System.Windows.Forms.ToolStripSystemRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs e)
at System.Windows.Forms.ToolStripRenderer.DrawToolStripBackground(ToolStripRenderEventArgs e)
at System.Windows.Forms.ToolStrip.OnPaintBackground(PaintEventArgs e)
at System.Windows.Forms.StatusStrip.OnPaintBackground(PaintEventArgs e)
at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle, Region transparentRegion)
at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backColor, Point scrollOffset)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle)
at System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs pevent)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.StatusStrip.RightToLeftLayoutGrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
dmProduction
Assembly Version: 1.0.0.2
Win32 Version: 1.0.0.2
CodeBase: file:///D:/Program%20Files/XXXX系统/dmProduction.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
ClassMyDate
Assembly Version: 1.0.0.4
Win32 Version: 1.0.0.4
CodeBase: file:///D:/Program%20Files/XXXX系统/ClassMyDate.DLL
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
cplan
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Program%20Files/XXXX系统/cplan.DLL
----------------------------------------
taskprocess
Assembly Version: 1.0.0.3
Win32 Version: 1.0.0.3
CodeBase: file:///D:/Program%20Files/XXX系统/taskprocess.DLL
----------------------------------------
zgraph
Assembly Version: 1.0.0.1
Win32 Version: 1.0.0.1
CodeBase: file:///D:/Program%20Files/XXXX系统/zgraph.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


zl194 2009-12-28
  • 打赏
  • 举报
回复
等我去超一下,错误原文。
加载更多回复(13)
内容概要:本文介绍了一个基于Java+Vue的制造工艺卡片电子化与防错提示系统的设计与实现,旨在解决传统纸质工艺卡片在版本管理、操作一致性、质量追溯等方面的不足。系统通过构建电子工艺卡为核心载体,整合产品、工艺、设备、物料、人员、检验等多维数据,实现工艺文件的在线编制、审批与发布,并利用规则引擎对开工、参数录入、报工等关键环节进行实时校验与分级防错提示。系统采用分层架构设计,前端使用Vue实现交互界面,后端基于Spring Boot提供服务支持,数据库采用关系型结构保障数据一致性。核心功能包括参数范围校验、前序工序完成判断、人员资质有效性检查、风险评分模型与提示等级聚合机制,并通过事件驱动的追溯模型实现全过程制造履历记录与分析。项目还提供了完整的领域模型、防错规则引擎、数据生成代码示例,支持与MES、条码系统等集成,助力企业实现制造过程数字化、标准化与智能化。; 适合人群:具备一定Java和Vue开发基础,从事制造业信息化、MES系统开发、工业软件研发的相关技术人员,以及关注智能制造、工艺管理数字化转型的工程师与管理者。; 使用场景及目标:①替代传统纸质工艺卡,实现工艺文件的集中管控与版本一致性;②在生产过程中自动校验人员、设备、物料、参数等是否符合工艺要求,预防人为错误;③建立全流程制造数据追溯体系,支持质量问题快速定位与根因分析;④通过风险评分与数据分析优化工艺稳定性与生产效率。; 阅读建议:此资源包含完整的系统架构设计、核心模型说明及可运行的代码片段,建议开发者结合实际制造场景理解各模块设计逻辑,重点掌握规则引擎的实现方式与数据流转机制,并可通过提供的数据生成工具模拟测试系统行为,进一步拓展至真实产线应用。
在当今全球气候变化的大背景下,对气候数据的分析和研究显得尤为重要。"ClimateDataToolbox"(CDT)作为一个专业的工具箱,为科研人员、环境学者以及政策制定者提供了强大的数据处理和分析能力。这款工具箱旨在简化气候数据的获取、管理和应用过程,从而帮助用户更好地理解地球气候系统的变化。 CDT的核心功能主要包括以下几个方面: 1. 数据获取:CDT能够便捷地连接到多个气候数据源,包括但不限于NASA、NOAA等权威机构,用户可以直接在工具箱中下载并导入各种气候模型输出数据、观测数据以及历史气候数据。 2. 数据预处理:工具箱内置了多种数据清洗和格式转换功能,可以处理缺失值、异常值,并将不同格式的数据统一,为后续分析做好准备。 3. 数据可视化:CDT提供了丰富的图形绘制选项,用户可以创建气候图、时间序列图、空间分布图等多种图表,直观展示气候变量的变化趋势和空间格局。 4. 数据分析:CDT支持对气候数据进行统计分析,如趋势分析、相关性分析、空间统计等,帮助用户深入探究气候现象背后的规律。 5. 模型应用:对于气候模型的使用者,CDT可以协助进行模型结果的比较和评估,比如通过对比不同气候模型的预测结果,分析其差异和一致性。 6. 地图制作与地理信息系统集成:CDT可以与GIS软件无缝对接,用户可以利用其制作高精度的地图,用于展示气候变量的地理分布,同时进行空间分析。 7. 教学与科普:CDT不仅适用于专业研究,也适合教学和科普活动,通过直观的界面和操作,让气候变化的理解更加直观易懂。 通过使用ClimateDataToolbox,用户能够高效地进行气候数据分析,提升研究效率,为应对气候变化提供科学依据。无论你是从事气候研究的学者,还是关注环保的公众,CDT都能成为你探索气候世界的得力助手。 在实际使用中,"ClimateDataToolbox.m

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧