Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi, I need to load multiple image in a window, the problem is when I'm loading so many images, lets say about 500 or more images it throws out of memory exception, another problem is the height property of the control is only limited to about 32,000, when I try to add many pictureBox it does not fit in the panel control and some pictureBox are not display, here's my codes ..
private void Form1_Load(object sender, EventArgs e)
{
    string imageDirectory = @"c:\temp\myImages";

    string[] imageFileList = Directory.GetFiles(imageDirectory);

    int iCtr = 0;
    foreach (string imageFile in imageFileList)
    {
        PictureBox eachPictureBox = new PictureBox();
        eachPictureBox.Size = new Size(850, 1100);
        eachPictureBox.Location = new Point(1, iCtr * 1100 + 1);
        eachPictureBox.Image = Image.FromFile(imageFile);
        iCtr++;

        panel1.Controls.Add(eachPictureBox);

    }

}


I try to load it when the window form loads, any tips will be much appreciated, thanks ..
Posted

Well, you kind of have your answer. What earthly reason could you have for loading so many images ? You can't do anything about the max size of a panel, you could try using a naturally scrollable control, which may not have a limit b.c it may not actually all exist visually at once.

You can't do anything to change the fact that each image uses a particular amount of RAM, or that the RAM on your machine has a finite limit. Your best bet IMO would be to create your own scrollable control, which loads the visible images as you scroll ( probably page by page ), and cleans up it's memory as it stops showing the old images.
 
Share this answer
 
Hi triskellionheart,

You can use the virtualizing concept to load the images as mentioned by Christian. One of the above two concept mentioned by him will help you.
 
Share this answer
 
Hi,

When u are reading from folder files it picks sum hidden file as well like desktop.ini etc hence the error
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900