GDI + System.Drawing.Bitmap给出错误参数无效间歇性

编程入门 行业动态 更新时间:2024-10-14 04:26:24
本文介绍了GDI + System.Drawing.Bitmap给出错误参数无效间歇性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ASP.Net应用程序,做一些这方面的C#code:

I have some C# code in an ASP.Net application that does this:

BMP位图=新位图(1184,1900);

Bitmap bmp = new Bitmap(1184, 1900);

和偶尔它抛出一个异常参数无效。现在,我一直在周围的Googling显然GDI +是臭名昭著的随机抛出异常,很多人都有过这样的问题,但没有人有一个解决方案吧!我检查了系统,它有大量的RAM和交换空间。现在,在过去,如果我做了一个IISRESET,然后问题消失,但它回来了几天。但我不认为我已经引起了内存泄漏,因为正如我上面说的有很多RAM +免费互换。

And occasionally it throws an exception "Parameter is not valid". Now i've been googling around and apparently GDI+ is infamous for throwing random exceptions, and lots of people have had this problem, but nobody has a solution to it! I've checked the system and it has plenty of both RAM and swap space. Now in the past if i do an 'iisreset' then the problem goes away, but it comes back in a few days. But i'm not convinced i've caused a memory leak, because as i say above there is plenty of ram+swap free.

任何人有什么办法呢?

推荐答案

停止使用GDI +,并开始使用WPF成像类(.NET 3.0)。这些都是GDI +类的大清理和调整性能。此外,它设置了一个位图链,让您可以轻松地以有效的方式进行对位多个动作。

Stop using GDI+ and start using the WPF Imaging classes (.NET 3.0). These are a major cleanup of the GDI+ classes and tuned for performance. Additionally, it sets up a "bitmap chain" that allows you to easily perform multiple actions on the bitmap in an efficient manner.

查找更多阅读关于BitmapSource

下面是一个空白的位图只是在等待接受一些像素开始的例子:

Here's an example of starting with a blank bitmap just waiting to receive some pixels:

using System.Windows.Media.Imaging; class Program { public static void Main(string[] args) { var bmp = new WriteableBitmap(1184, 1900, 96.0, 96.0, PixelFormat.Bgr32, null); } }

更多推荐

GDI + System.Drawing.Bitmap给出错误参数无效间歇性

本文发布于:2023-11-12 10:59:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581296.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间歇性   错误   参数   System   GDI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!