Out of Memory exception
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Out of Memory exception

  1. #1
    Join Date
    Oct 2010
    Posts
    23

    Out of Memory exception

    I want to add images in a panel. Each image size is 5 to 6 MB. If I add more than 35 images then it shows error that "Out of Memory". This exceptions occur when Image.FromFile(string) is executed. If less than 35 images is loaded then no error shows.

    if (DialogResult.OK == ofdLoadFromHDD.ShowDialog())
    {

    string[] strArray = ofdLoadFromHDD.FileNames;
    int count = strArray.Count();
    DynamicGroupBox objDGB = new DynamicGroupBox(scrolledValue);
    GroupBox gB = new GroupBox();

    try
    {
    for (int i = 0; i < count; i++)
    {
    Bitmap bmp = (Bitmap)Image.FromFile(strArray[i]);

    CommonInformation.SCANNING_NUMBER++;
    objCommonUtility.replaceImageIntoDB(bmp, CommonInformation.SCANNING_NUMBER.ToString());

    gB = objDGB.createGroupBox(bmp, CommonInformation.SCANNING_NUMBER, false);

    pnlImageContainer.Controls.Add(gB);

    }
    gB.Select();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    CommonInformation.SCANNING_NUMBER--;
    }
    }


    Development Environment:
    Windows XP Professional Edition
    VS 2010, C#, .NET framework 4.0

    How can I solve this problem?

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,000

    Re: Out of Memory exception

    Probably what is happening is that they are 5-6 MB JPEG files (compressed representation on disk) which are expanded to high-resolution Bitmaps (uncompressed internal representation). You should open them and immediately re-scale them (before opening the next one), see this post: http://www.peterprovost.org/blog/pos...mage-in-C.aspx
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center