"Out of memory exception when loading image with bitmap
-
Hello all I have a mysql table with some rows in it that contain a path to a jpg file. Here is a example of the path: images/portfolio/lille_ilveaWebshop.jpg The file excists on the webhost so that is not a problem. I am loading the jpg file into a bitmap in a foreach. It works fine when I am on a local server, but when I upload it to my webhost it says: <quote>Server Error in '/' Application. Out of memory. Exception Details: System.OutOfMemoryException: Out of memory. [OutOfMemoryException: Out of memory.] System.Drawing.Bitmap..ctor(String filename) +376480 Referencer.Page_Load(Object sender, EventArgs e) +561 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627</quote> I cant seem to figure out just why it would do that. Here is the code I am using: foreach ( DataRow Row in objPortFac.VisReference(refKatID).Rows) { // Create a new bitmap with the path from the row // fldStortBillede is the field that contains the path Bitmap objStortBillede = new Bitmap(Server.MapPath(Row["fldStortBillede"].ToString())); // Dispose the bitmap after use objStortBillede.Dispose(); } Any suggestions?
-
Hello all I have a mysql table with some rows in it that contain a path to a jpg file. Here is a example of the path: images/portfolio/lille_ilveaWebshop.jpg The file excists on the webhost so that is not a problem. I am loading the jpg file into a bitmap in a foreach. It works fine when I am on a local server, but when I upload it to my webhost it says: <quote>Server Error in '/' Application. Out of memory. Exception Details: System.OutOfMemoryException: Out of memory. [OutOfMemoryException: Out of memory.] System.Drawing.Bitmap..ctor(String filename) +376480 Referencer.Page_Load(Object sender, EventArgs e) +561 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627</quote> I cant seem to figure out just why it would do that. Here is the code I am using: foreach ( DataRow Row in objPortFac.VisReference(refKatID).Rows) { // Create a new bitmap with the path from the row // fldStortBillede is the field that contains the path Bitmap objStortBillede = new Bitmap(Server.MapPath(Row["fldStortBillede"].ToString())); // Dispose the bitmap after use objStortBillede.Dispose(); } Any suggestions?
Hi, some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid. I don't know what Server.MapPath is assumed to do, nor how valid its result is. Split the statement in simpler ones and debug. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Hi, some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid. I don't know what Server.MapPath is assumed to do, nor how valid its result is. Split the statement in simpler ones and debug. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
The "new bitmap" needs a full path an images/something/blah.jpg doesnt work. I am using Server.MapPath to find the full path
-
The "new bitmap" needs a full path an images/something/blah.jpg doesnt work. I am using Server.MapPath to find the full path
Have you checked the value of
Server.MapPath(Row["fldStortBillede"].ToString()
? MSDN: "For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE." :)Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Have you checked the value of
Server.MapPath(Row["fldStortBillede"].ToString()
? MSDN: "For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE." :)Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
The value on localhost is: D:\Skole\DotNet\Portfolio\Portfolio\images\portfolio\stor_cronaldoHjemmeside.jpg And on the webhost it is: d:\web\localuser\dumpen.dk\public_html\images\portfolio\stor_cronaldoHjemmeside.jpg It works with 2 or 3 images but with more then that the error occours
-
The value on localhost is: D:\Skole\DotNet\Portfolio\Portfolio\images\portfolio\stor_cronaldoHjemmeside.jpg And on the webhost it is: d:\web\localuser\dumpen.dk\public_html\images\portfolio\stor_cronaldoHjemmeside.jpg It works with 2 or 3 images but with more then that the error occours
is it always the same image that fails, if so it got damaged. try changing the order just to see what happens. are these images large, compared to your system (is it a mobile Windows system with limited RAM?). :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
is it always the same image that fails, if so it got damaged. try changing the order just to see what happens. are these images large, compared to your system (is it a mobile Windows system with limited RAM?). :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
I'm also having the same Problem. In my local it is working properly. But in server, it is throwing out of memory exception. i got this exception even though the memory is available in server. Graphics g = Graphics.FromImage(source); try { g.DrawImageUnscaled(original, 0, 0); } finally { ((IDisposable)g).Dispose(); } This is the code i'm using. Any solutions to this issue? Thanks in advance :)
-
I'm also having the same Problem. In my local it is working properly. But in server, it is throwing out of memory exception. i got this exception even though the memory is available in server. Graphics g = Graphics.FromImage(source); try { g.DrawImageUnscaled(original, 0, 0); } finally { ((IDisposable)g).Dispose(); } This is the code i'm using. Any solutions to this issue? Thanks in advance :)
insufficient information. IMO DrawImageUnscaled is more critical than DrawImage, as the resolution may be screwed inside the image (both source and original). Try DrawImage instead. And log all image parameters, to see if there ever is anything abnormal. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Hi, some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid. I don't know what Server.MapPath is assumed to do, nor how valid its result is. Split the statement in simpler ones and debug. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
Luc Pattyn wrote:
some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid.
Nice. 8 years later, and this post was quite relevant for me, in that it really wasn't an OOM error.
Latest Articles:
A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework -
Luc Pattyn wrote:
some image operators (e.g. Image.FromFile) throw an OOM Exception when the data is not valid.
Nice. 8 years later, and this post was quite relevant for me, in that it really wasn't an OOM error.
Latest Articles:
A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework:rose: Today, I need to fix that statement; it should read:
some image operators (e.g. Image.FromFile) MAY throw an OOM Exception when the data is not valid.
There is no guarantee an OOM will occur on every damaged image! :)
Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.