GDI + System.Drawing.Bitmap给出错误参数无效间歇性 [英] GDI+ System.Drawing.Bitmap gives error Parameter is not valid intermittently

查看:663
本文介绍了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.

查找更多阅读关于<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx\">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给出错误参数无效间歇性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆