locked
Running out of memory RRS feed

  • Question

  • User673681018 posted
    Hi all, I am creating simple application to shrink images. Here is my function that I call everytime I find a jpeg in the folder.

    private void ResizeImages(Image imgImage, int intWidth,int intHeight, string SavePath)

    {

    Bitmap b = new Bitmap(imgImage);

    Bitmap result = new Bitmap(intWidth, intHeight);

    Graphics g = Graphics.FromImage(result);

    g.Clear(System.Drawing.Color.White);

    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

    g.DrawImage(b,0,0,intWidth, intHeight);

    result.Save(SavePath,System.Drawing.Imaging.ImageFormat.Jpeg);

    result.Dispose();

    b.Dispose();

    g.Dispose();

    }

    For some reason, around 178 image, the application runs out of memory. Can someone tell me why?

    Friday, August 12, 2005 2:12 AM

All replies

  • User1109032460 posted
    One quick question. The Image object that is passed in - where does it come from, and who cleans it up?
    Friday, August 12, 2005 8:58 AM
  • User673681018 posted

    It's in a loop. Something like bellow:

    foreach( folderinfo folder in directoryinfo.folders()){
    //bla bla bla
    }

    Ok, I will try to dispose the image object to and see where that goes. I thought I got all of them, but I missed the image object. Thanks, for your support.

    Friday, August 12, 2005 12:44 PM
  • User673681018 posted

    Disposing the Image object worked. Thanks for all your help.

    Sunday, August 14, 2005 3:04 PM