Dear all,
I made a c# program for my friend's wedding. It slides all photos in
specified folder automatically. To roll the pictures smoothly I firstly scan
and store all pictures in RAM and push one by one to PictureBox control and
display it when the Timer control ticks. Coding like this:
------------------------------------------------------
IList<Imagephot oes = new List<Image>();
LoadPhotoes(Pho toSlide.Propert ies.Settings.De fault.PhotoFold er, ref
photoes);
private void LoadPhotoes(str ing folderPath, ref IList<Imagephot oes)
{
DirectoryInfo currentDir = new DirectoryInfo(f olderPath);
if (currentDir.Exi sts)
{
DirectoryInfo[] subDirs = currentDir.GetD irectories();
foreach (DirectoryInfo dir in subDirs)
{
LoadPhotoes(dir .FullName, ref photoes);
}
FileInfo[] files = currentDir.GetF iles();
foreach (FileInfo file in files)
{
string fileExt = file.Extension. ToUpper();
if (fileExt == ".JPG" || fileExt == ".JPEG")
{
using (FileStream stream = file.OpenRead() )
{
photoes.Add(Ima ge.FromStream(s tream));
}
}
}
}
}
.... ...
this.pictureBox 1.Image = GetSlidePhoto(p hotoes, lastPhotoIndex) ;
----------------------------------
The code can work, but it sucks the memory very much. As you see, this line
of code -
/* photoes.Add(Ima ge.FromStream(s tream)); */ will stack all Image objects
in RAM. In my test, I slide about 50 pictures which are total about 50 Mb( ~
1 Mb for 1 picture), it costs 300Mb RAM to run it.
Do you have any idea to improve this small program? Thanks.
--
Sincerely,
Mike Chen
http://chagel.com