有助于解决“内存不足”异常调用DrawImage的时候 [英] Help to resolve 'Out of memory' exception when calling DrawImage

查看:5275
本文介绍了有助于解决“内存不足”异常调用DrawImage的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一成左右的使用者在使用我们的应用程序出现突然死机。该日志显示以下异常,我已经看到了迄今为​​止唯一的共同点是,它们都具有XP SP3。

在此先感谢

内存不足。

   在System.Drawing.Graphics.CheckErrorStatus(的Int32状态)
   在System.Drawing.Graphics.DrawImage(图像图像,矩形destRect,的Int32 srcX,的Int32 srcY,的Int32 srcWidth,的Int32 srcHeight,GraphicsUnit srcUnit,ImageAttributes imageAttrs,DrawImageAbort回调,IntPtr的callbackData)
   在System.Drawing.Graphics.DrawImage(图像图像,矩形destRect,的Int32 srcX,的Int32 srcY,的Int32 srcWidth,的Int32 srcHeight,GraphicsUnit srcUnit,ImageAttributes imageAttr,DrawImageAbort回调)
   在System.Drawing.Graphics.DrawImage(图像图像,矩形destRect,的Int32 srcX,的Int32 srcY,的Int32 srcWidth,的Int32 srcHeight,GraphicsUnit srcUnit,ImageAttributes imageAttr)
   在System.Windows.Forms.ControlPaint.DrawBackgroundImage(图形克,图片和backgroundImage,颜色背景色,ImageLayout backgroundImageLayout,矩形范围,矩形CLI $ P $厘,点scrollOffset,从右至左从右至左)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形,颜色背景色,点scrollOffset)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形)
   在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs的pevent)
   在System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgs的E)
   在System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs的E,长方形矩形,地区transparentRegion)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形,颜色背景色,点scrollOffset)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形)
   在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs的pevent)
   在System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgs的E)
   在System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs的E,长方形矩形,地区transparentRegion)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形,颜色背景色,点scrollOffset)
   在System.Windows.Forms.Control.PaintBackground(PaintEventArgs的E,长方形矩形)
   在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs的pevent)
   在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs的E,Int16的层,布尔disposeEventArgs)
   在System.Windows.Forms.Control.WmPaint(消息&M)
   在System.Windows.Forms.Control.WndProc(消息&M)
   在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&M)
   在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&M)
   在System.Windows.Forms.NativeWindow.Callback(IntPtr的的HWND,味精的Int32,IntPtr的WPARAM,IntPtr的LPARAM)

运行系统信息
----------------------------
NAME = Windows XP中
版=首页
服务包= Service Pack 3的
版本= 5.1.2600.196608
位= 32

解决方案

我敢肯定,你想通了这一点了,但如果你没有我们打了同样的问题。这是在GDI +中的错误,这可以作为一种解决方法。不幸的是我不知道的为什么,但这些各种各样的问题,我倾向于更关心,它的固定少,为什么它的固定。 ;)

 图像= image.GetThumbnailImage(image.Width,image.Height,空,IntPtr.Zero);
 

显然,这一呼吁调整的PixelFormat并把图像的格式的DrawImage的图像列表的使用可以处理。

来源: http://siderite.blogspot.com/2009/09/outofmemoryexception-in.html

About one percent of our users experience sudden crash while using our application. The logs show below exception, the only thing in common that I've seen so far is that, they all have XP SP3.

Thanks in advance

Out of memory.

   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
   at System.Windows.Forms.ControlPaint.DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
   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.ScrollableControl.OnPaintBackground(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle, Region transparentRegion)
   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.ScrollableControl.OnPaintBackground(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs e, Rectangle rectangle, Region transparentRegion)
   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.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)

Operation System Information
----------------------------
Name = Windows XP
Edition = Home
Service Pack = Service Pack 3
Version = 5.1.2600.196608
Bits = 32

解决方案

I'm sure you've figured this out by now, but in case you haven't we hit the same issue. It's a bug in GDI+ and this works as a workaround. Unfortunately I don't know why but with these sorts of issues I tend to care more that it's fixed and less why it's fixed. ;)

image = image.GetThumbnailImage(image.Width, image.Height, null, IntPtr.Zero);

Apparently that call adjusts the PixelFormat and puts the image in a format that the imagelist's usage of DrawImage can handle.

From: http://siderite.blogspot.com/2009/09/outofmemoryexception-in.html

这篇关于有助于解决“内存不足”异常调用DrawImage的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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