我有一个 .NET 2.0 应用程序,在 XP 和 Vista 上运行得很好,但在 Windows 7 RC (x64) 上它崩溃并出现以下错误:
异常信息
异常类型:System.OutOfMemoryException
消息:内存不足。
数据:System.Collections.ListDictionaryInternal
TargetSite:Void .ctor(System.Drawing.Image,System.Drawing.Drawing2D.WrapMode)
帮助链接:NULL
来源:System.Drawing
堆栈跟踪信息
在 System.Drawing.TextureBrush..ctor(图像图像,WrapMode 包裹模式)
在System.Windows.Forms.ControlPaint.DrawBackgroundImage(图形g,图像backgroundImage,颜色backColor,ImageLayout backgroundImageLayout,矩形边界,矩形clipRect,点scrollOffset,RightToLeft rightToLeft)
在System.Windows.Forms.Control.PaintBackground(PaintEventArgs e,矩形矩形,颜色backColor,点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.PaintWithErrorHandling(PaintEventArgs e,Int16层,布尔disposeEventArgs)
在 System.Windows.Forms.Control.WmPaint(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
关于为什么会发生这种情况,或者我如何围绕它进行编程有什么想法吗?它只是画了一个标准的winform,没有特殊的背景。
更新:
我发现这只是当BackgroundImageLayout = ImageLayout.Tile(这也是默认值)时出现的问题。将其设置为“缩放”或“居中”,问题就会消失。但这非常令人不满意,因为我需要它来平铺。
我有类似的问题。就我而言,我已经处理掉了加载图像的 MemoryStream。
//The following throws and OutOfMemoryException at the TextureBrush.ctor():
/*someBytes and g declared somewhere up here*/
Bitmap myBmp = null;
using(MemoryStream ms = new MemoryStream(someBytes))
myBmp = new Bitmap(ms);
if(myBmp != null) //that's right it's not null.
using(TextureBrush tb = new TextureBrush(myBmp)) //OutOfMemoryException thrown
g.FillRectangle(tb,0,0,50,50);
//This code does not throw the same error:
/*someBytes and g declared somewhere up here*/
MemoryStream ms = new MemoryStream(someBytes);
Bitmap myBmp = new Bitmap(ms);
if(myBmp != null)
using(TextureBrush tb = new TextureBrush(myBmp))
g.FillRectangle(tb,0,0,50,50);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)