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.
Code:
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?