Windows 7 Windows 7 TextureBrush..ctor()错误

Windows 7 Windows 7 TextureBrush..ctor()错误,windows-7,.net-2.0,crash,Windows 7,.net 2.0,Crash,我有一个.NET 2.0应用程序,它在XP和Vista上运行得很好,但在Windows 7 RC(x64)上它崩溃了,出现以下错误: 例外信息 异常类型:System.OutOfMemoryException 消息:内存不足。 数据:System.Collections.ListDictionaryInternal 目标站点:Void.ctor(System.Drawing.Image,System.Drawing.Drawing2D.WrapMode) 帮助链接:空 资料来源:系统图 堆栈跟

我有一个.NET 2.0应用程序,它在XP和Vista上运行得很好,但在Windows 7 RC(x64)上它崩溃了,出现以下错误:

例外信息


异常类型:System.OutOfMemoryException 消息:内存不足。 数据:System.Collections.ListDictionaryInternal 目标站点:Void.ctor(System.Drawing.Image,System.Drawing.Drawing2D.WrapMode) 帮助链接:空 资料来源:系统图

堆栈跟踪信息


在System.Drawing.TextureBrush..ctor(图像图像,WrapMode WrapMode) 在System.Windows.Forms.ControlPaint.DruckGroundImage(图形g、图像背景图像、颜色背景色、图像布局背景图像布局、矩形边界、矩形clipRect、点滚动偏移、右至左至右至左) 在System.Windows.Forms.Control.PaintBackground(PaintEventArgs e、矩形、彩色背景、点滚动偏移) 位于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.PaintEventArgs处理中(PaintEventArgs e、Int16层、Boolean 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时的问题,这也是默认值。将其设置为“缩放”或“居中”,则问题将消失。但这很不令人满意,因为我需要它来平铺。

结果证明,解决这个问题的方法与用作背景的PNG文件本身有关。 我只是用Paint.NET打开它并重新保存,然后把它放回项目中,它就工作了


不确定发生了什么变化,但它解决了问题。

我也遇到了类似的问题。在我的情况下,我已经处理了我的记忆流,我从中加载了图像

//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);

在调用TextureBrush类进行平铺之前,请不要处理图像或关闭从中获取图像的filestream对象。否则,TextureBrush类将抛出内存不足异常


因此,更好的方法是通过调用TextureBrush图像来显示平铺图像,然后在windows窗体的绘制事件中关闭filestream对象。

它在XP和Vista 64位上运行良好吗?是的,它在XP和Vista的32位和64位版本上运行良好。谢谢(这是在黑暗中拍摄的,最近在交叉拱问题上出现了一些类似的问题。)对不起,没有想法。这正是我的问题。懂.net“引擎盖下”的人会费心解释这种行为吗?刚刚遇到这种情况。我支持@Dinei,有人知道为什么会发生这种情况吗?我也很好奇。