Asked by:
Out of Memory Error when Creating thumbnail of image with size more than 7000 pixcel

Question
-
User-615990677 posted
Hi Guies, I was doing wonders till I stucked with this error, can any body help.
Issue is I am creating thumbnail of image on the fly and showing on my pages. When the image height/width exceed 7000 pixcel I get out of memory error.
I am attaching the code I am using
using
System;using
System.Data;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;using
System.Drawing;using
System.Drawing.Imaging;public
partial class CreateThumbNail : System.Web.UI.Page{
private void Page_Load(object sender, System.EventArgs e){
string Image = Request.QueryString["Image"];if (Image == null){
this.ErrorResult(); return;}
{
Response.Write("Bmp is null");Response.End();
// this.ErrorResult(); return;}
Response.ContentType =
"image/jpeg"; bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);bmp.Dispose();
}
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
}
{
System.Drawing.Bitmap bmpOut = null; //try //{ Bitmap loBMP = new Bitmap(lcFilename); ImageFormat loFormat = loBMP.RawFormat;{
lnRatio = (decimal)lnWidth / loBMP.Width;lnNewWidth = lnWidth;
decimal lnTemp = loBMP.Height * lnRatio;lnNewHeight = (int)lnTemp;}
else{
lnRatio = (decimal)lnHeight / loBMP.Height;lnNewHeight = lnHeight;
decimal lnTemp = loBMP.Width * lnRatio;lnNewWidth = (
int)lnTemp;}
g.FillRectangle(
Brushes.White, 0, 0, lnNewWidth, lnNewHeight);g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
loBMP.Dispose();
//} //catch //{ // return null; //}}
}
Wednesday, February 18, 2009 8:13 AM
All replies
-
User-1509636757 posted
string Path = Server.MapPath(Request.ApplicationPath) + "\\" + Image;check this path validity. i mean whether file is exists there or not..
GDI+ tends to throw OutOfMemoryExceptions whenever something goes wrong event if that's got nothing to do with a memory problem. I *think* that you might get an OutOfMemoryException if the image is corrupted or has an unsuported format. I would investigate this first.
Referenced Link > Windows Service - Out of memory - .NET
hope it helps./.
Wednesday, February 18, 2009 8:33 AM -
User-615990677 posted
Thanks for reply
But the image does exist. If I just decrease the size of the image, thumbnail will start genrating. All the images with size more than 7000 pixcels the error arises.
Wednesday, February 18, 2009 11:16 AM -
User-1509636757 posted
can you please look at the innerexception and post the details?
Wednesday, February 18, 2009 12:28 PM -
User-615990677 posted
Can you please elobarate little more, well I am giving the line specific error
Exception Details: System.OutOfMemoryException: Out of memory.
g.DrawImage(loBMP, 0, 0, Convert.ToInt32(CurrentimgWidth), Convert.ToInt32(CurrentimgHeight))
IS this what you were asking for.
Monday, February 23, 2009 5:43 AM