.net2.0 与 .net 4.0 gdi+不同之处?

发布于 2024-10-06 00:50:28 字数 1962 浏览 1 评论 0原文

我有一个非常奇怪的问题,我有一个应用程序需要对图片进行大量 GDI+ 操作。例如裁剪缩放等。我的应用程序在 .net 2.0 中运行良好,但在 .net 4.0 中我收到用户的报告,称它因 gdi+“内存不足”错误而崩溃。现在我知道“内存不足”gdi+ 错误是很多错误的统称,但为什么它在 .net 2.0 中工作而不是在 .net 4 上工作。

具体来说,我有一个在其顶部绘制“图层”的控件彼此以创建组合位图。该控件在 .net 2.0 中工作得很好,但在 .net 4 中则不然。

当我从文件系统加载 10 兆像素 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>

谢谢您的耐心,因为这是我的第一个问题

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

其中比例 1s 4 表示 400%

I have a really weird problem where I have an application that does a lot of involved GDI+ manipulation of pictures. Such as cropping zooming etc. My application works fine in .net 2.0, but in .net 4.0 I am getting reports from my users that it is crashing with a gdi+ "out of memory" error. Now I know that the "out of memory" gdi+ error is a catch all for alot of errors, but why would it work in .net 2.0 and NOT on .net 4.

Specifically i have a control that draws "layers" on top of each other in order to create a composed bitmap. this control worked just fine in .net 2.0 and NOT in .net 4.

It secifically happens when I have a 10 megapixel jpeg loaded from the file system and I am applying a zoom and transform to the image.

to give even more detail. g.draw with a matrix scale of 4 meaning 400% bigger with any rotation will return this "out of memory error.

It only happens on xp boxes and NOT on windows 7 boxes. What could be the difference here?

any takers...

here is the extent of my stack trace logged from the caught exception.

  <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>

Thank you for your time. be gentle as this is my 1st question here.

0xa3 I have no stack trace at the moment, but the exact g.draw call is below:

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

where scale 1s 4 for 400%

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2024-10-13 00:50:28

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

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

I faced similar issues. In my case the problem was LOH fragmentation. Maybe this will help: Large Object Heap Fragmentation

Basically you newer know for sure how memory is allocated. Sometimes you will get away with processing some large set of data, sometimes your app will fail. The problem is more likely to pop up if your program runs for long period of time and processes large amount of data. You mentioned 10 megapixels image - if you do a lot of processing with such files it's fairly easy to hit the LOH issue.

老街孤人 2024-10-13 00:50:28

System.Drawing.Graphics.DrawImage直接调用名为“GdipDrawImageRectRectI”的gdiplus函数。无论您使用哪种 .NET Framework,GDI+ 的版本并不多,而且调用方式都是相同的。也许这篇文章可以帮助:最新GDI+ 版本和支持信息

如果系统是 X86 或 X64,GDI+ 也可能不同。您要确保始终比较同一事物。
也许您可以跟踪进程中加载​​了哪些 GDI+ DLL,以帮助解决这个问题。

System.Drawing.Graphics.DrawImage directly calls a gdiplus function named "GdipDrawImageRectRectI". Whatever .NET Framework you use, there are not many versions of GDI+ and the way it's called is the same. Maybe this post can help: Latest version of GDI+ and support information

GDI+ may also be different if the system is X86 or X64. You want to make sure you're always comparing the same thing.
Maybe you can track what GDI+ DLL is loaded in your process to help sort this out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文