===============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;


}


谁能帮我分析分析是怎么回事呢,或者这种不是实时出现的错误怎么测试呢。
...全文
332 33 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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)
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver
类很多,不写全了。。下载下来好好看 ----------Database-------------- 1.DataTable帮助类(DataTableHelper.cs) 2.Access数据库文件操作辅助类(JetAccessUtil.cs) 5.查询条件组合辅助类(SearchCondition.cs) 6.查询信息实体类(SearchInfo.cs) 8.Sql命令操作函数(可用于安装程序的时候数据库脚本执行)(SqlScriptHelper.cs) ----------Device-------------- 声音播放辅助类(AudioHelper.cs) 摄像头操作辅助类,包括开启、关闭、抓图、设置等功能(Camera.cs) 提供用于操作【剪切板】的方法(ClipboardHelper.cs) 获取电脑信息(Computer.cs) 提供用户硬件唯一信息的辅助类(FingerprintHelper.cs) 读取指定盘符的硬盘序列号(HardwareInfoHelper.cs) 提供访问键盘当前状态的属性(KeyboardHelper.cs) 全局键盘钩子。这可以用来在全球范围内捕捉键盘输入。(KeyboardHook.cs) 模拟鼠标点击(MouseHelper.cs) 全局鼠标钩子。这可以用来在全球范围内捕获鼠标输入。(MouseHook.cs) MP3文件播放操作辅助类(MP3Helper.cs) 关联文件(ExtensionAttachUtil.cs) 注册文件关联的辅助类(FileAssociationsHelper.cs) 打开、保存文件对话框操作辅助类(FileDialogHelper.cs) 常用的文件操作辅助类FileUtil(FileUtil.cs) INI文件操作辅助类(INIFileUtil.cs) 独立存储操作辅助类(IsolatedStorageHelper.cs) 序列号操作辅助类(Serializer.cs) 获取一个对象,它提供用于访问经常引用的目录的属性。(SpecialDirectories.cs) 简单的Word操作对象(WordCombineUtil.cs) 这个类提供了一些实用的方法来转换XML和对象。(XmlConvertor.cs) XML操作类(XmlHelper.cs) ----------Format-------------- 参数验证的通用验证程序。(ArgumentValidation.cs) 这个类提供了实用方法的字节数组和图像之间的转换。(ByteImageConvertor.cs) byte字节数组操作辅助类(BytesTools.cs) 处理数据类型转换,数制转换、编码转换相关的类(ConvertHelper.cs) CRC校验辅助类(CRCUtils.cs) 枚举操作公共类(EnumHelper.cs) 身份证操作辅助类(IDCardHelper.cs) 检测字符编码的类(IdentifyEncoding.cs) RGB颜色操作辅助类(MyColors.cs) 日期操作类(MyDateTime.cs) 转换人民币大小金额辅助类(RMBUtil.cs) 常用的字符串常量(StringConstants.cs) 简要说明TextHelper。(StringUtil.cs) 获取中文字首字拼写,随机发生器,按指定概率随机执行操作(Util.cs) 各种输入格式验证辅助类(ValidateUtil.cs) ----------Network-------------- Cookie操作辅助类(CookieManger.cs) FTP操作辅助类(FTPHelper.cs) HTML操作类(HttpHelper.cs) 网页抓取帮助(HttpWebRequestHelper.cs) Net(NetworkUtil.cs) IE代理设置辅助类(ProxyHelper.cs) ----------Winform-------------- 跨线程的控件安全访问方式(CallCtrlWithThreadSafety.cs) CheckBoxList(CheckBoxListUtil.cs) 窗口管理类(ChildWinManagement.cs) 由马丁·米勒http://msdn.microsoft.com/en-us/library/ms996492.aspx提供一个简单的方法打印工作的一个RichTextBox一个帮手(ExRichTextBoxPrintHelper.cs) 显示,隐藏或关闭动画形式。(FormAnimator.cs) 对窗体进行冻结、解冻操作辅助类(FreezeWindowUtil.cs) 窗体全屏操作辅助类(FullScreenHelper.cs) GDI操作辅助类(GDI.cs) 提供静态方法来读取这两个文件夹和文件的系统图标。(IconReaderHelper.cs) 图片对象比较、缩放、缩略图、水印、压缩、转换、编码等操作辅助类(ImageHelper.cs) 输入法帮助,全角 转换为半角(ImeHelper.cs) Winform提示框 的摘要说明。(MessageUtil.cs) 包含互操作方法调用的应用程序中使用。(NativeMethods.cs) 托盘图标辅助类(NotifyIconHelper.cs) 打印机类(POSPrinter.cs) 图片、光标、图标、位图等资源操作辅助类(ResourceHelper.cs) RTF字符格式辅助类(RTFUtility.cs) 串口开发辅助类(SerialPortUtil.cs) 设置文本属性提供一个ToolStripStatusLabel(SafeToolStripLabel.cs) 只运行一个实例及系统自动启动辅助类(StartupHelper.cs) Web页面预览效果图片抓取辅助类(WebPageCapture.cs) 供Asp.Net直接调用的包装类(WebPreview.cs) 计算机重启、关电源、注销、关闭显示器辅助类(WindowsExitHelper.cs) 简单写了点,还有很多,希望能对大家有帮助 ================================================================================================ 本资料共包含以下附件: WHC.OrderWater.Commons.rar 公共类文档.docx
上次发了一个易语言内存生成验证码的源码,后来压力测试的时候发现多线程下程序会崩溃。原因是 GDI 在多线程创建hDC的时候,经常会失败,内存hDC只有一个工作区域,导致多线程冲突 所以后来研究了一段时间发现,多线程下不能用 GDI,需要用DGI+,虽然 DGI+的确是线程安全的,可是它保证安全的做法可能类似于我们易语言加许可区,所以严格意义上来说, DGI+也不是多线程的,只不过在多线程下是安全的而已 后来网上查找资料,得到了一个让人很沮丧的说法: 这是CSDN上的人说的,他说:听公司一个图形方面的大佬说过,图形绘制主流的技术,GDI、GDI+、OpenGL,D3D什么的都不支持多线程,同一时间内,只能有一个线程在屏幕绘制,所以,根本就没有什么多线程绘图这个玩意。。。 根据我这几天的测试,查看内存和CPU数据,也确实发现即使是GDI+,也只能单线程运行,多线程下也是排队进行绘图的,因为Windows只有一个画板。。。 好了,那就不纠结了,既然连OpenGL都不支持多线程绘图,那就老老实实的就这样用着吧 ============================================================================================ 本源码介绍: 还是跟上次一样,只有一个公开子程序,里面的参数做了一下调整 特点是 每个字符都可以用不同的字体,字体可以随时扩充,在哪里找到了什么好看的字体,直接安装到电脑里,然后把字体名称添加到参数里就可以了 理论上,如果经常更换字体,字体足够多的话,制作识别库是很头疼的一件事,这个用于易语言web开发很合适哟

111,112

社区成员

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

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

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