Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net2.0 vs .net 4.0 gdi+ difference?

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%

like image 903
Bryan Wilkins Avatar asked Nov 30 '10 21:11

Bryan Wilkins


People also ask

Is. net Framework 4. 8 backwards compatible with 4. 5?

NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the . NET Framework. In other words, apps and components built with previous versions will work without modification on the . NET Framework 4.5 and later versions.

Is. net 6. 0 backward-compatible?

0 is not backward compatible with older version of netcoreapps #19374.

Is. net 5 backwards compatible with. net Framework?

ASP.NET 5 is just the new Web stack reimagined; it's not backward compatible, at least not literally, although it doesn't sound like a brand-new paradigm shift to ASP.NET developers.

Does .NET 4 include 2?

Yes and no - you can run . NET 2 code on the . NET 4 runtime but they are separate runtime engines. Depending on how the installer checks for .


1 Answers

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.

like image 119
SiliconMind Avatar answered Sep 21 '22 12:09

SiliconMind