.net2.0 vs .net 4.0 gdi +差异?

Bry*_*ins 14 .net graphics system.drawing gdi+

我有一个非常奇怪的问题,我有一个应用程序,它做了很多涉及GDI +操作图片.如裁剪缩放等我的应用程序在.net 2.0中工作正常,但在.net 4.0我收到来自我的用户的报告,它崩溃了gdi +"内存不足"错误.现在我知道"内存不足"gdi +错误是一个很好的错误,但为什么它会在.net 2.0而不是.net 4上工作.

具体来说,我有一个控件,可以在彼此的顶部绘制"图层",以创建一个组合的位图.这个控件在.net 2.0中运行得很好而在.net 4中运行不正常.

当我从文件系统加载了一个1000万像素的jpeg并且我正在应用缩放和变换到图像时,它会发生这种情况.

提供更多细节.g.draw的矩阵比例为4意味着任何旋转都会增加400%将返回"内存不足错误".

它只发生在xp盒子而不是Windows 7盒子上.这可能有什么不同?

任何接受者......

这是从捕获的异常中记录的堆栈跟踪的范围.

  <Event>
    <TimeStamp>11/30/10 11:02:43.706</TimeStamp>
    <Source>APPro2</Source>
    <EventType>Error</EventType>
    <Message><![CDATA[##: OutOfMemoryException
Message:
Out of memory.

Stack Trace:
   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)
   at Colorvision.Graphics.Layers.Picture.DrawBig(Graphics g) in D:\Colorvision_Workspaces\Colorvision\Graphics\Layers\Picture.cs:line 321
   at Colorvision.Graphics.LayerCollection.DrawBig(Graphics e) in D:\Colorvision_Workspaces\Colorvision\Graphics\LayerCollection.cs:line 690]]></Message>
    <EventID>0</EventID>
  </Event>
Run Code Online (Sandbox Code Playgroud)

感谢您的时间.要温柔,因为这是我的第一个问题.

0xa3目前我没有堆栈跟踪,但确切的g.draw调用如下:

g.DrawImage(
    bmpBigPicture,
    new Rectangle(
        destBigX,
        destBigY,
        (int)(destBigWidth*Scale),
        (int)(destBigHeight*Scale)),
    0,
    0,
    bmpBigPicture.Width,
    bmpBigPicture.Height,
    GraphicsUnit.Pixel,
    imgAttribs
); 
Run Code Online (Sandbox Code Playgroud)

其中规模1s 4为400%

Sil*_*ind 1

我遇到了类似的问题。就我而言,问题是 LOH 碎片。也许这会有所帮助:大型对象堆碎片

基本上,您新手肯定知道内存是如何分配的。有时您可以处理一些大型数据集,有时您的应用程序会失败。如果您的程序运行时间较长并处理大量数据,则更有可能出现此问题。您提到了 10 兆像素图像 - 如果您对此类文件进行大量处理,则很容易遇到 LOH 问题。