473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to optimize memory on my photo slide program

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<Imagephotoes = new List<Image>();
LoadPhotoes(PhotoSlide.Properties.Settings.Default .PhotoFolder, ref
photoes);

private void LoadPhotoes(string folderPath, ref IList<Imagephotoes)
{
DirectoryInfo currentDir = new DirectoryInfo(folderPath);
if (currentDir.Exists)
{
DirectoryInfo[] subDirs = currentDir.GetDirectories();
foreach (DirectoryInfo dir in subDirs)
{
LoadPhotoes(dir.FullName, ref photoes);
}

FileInfo[] files = currentDir.GetFiles();
foreach (FileInfo file in files)
{
string fileExt = file.Extension.ToUpper();
if (fileExt == ".JPG" || fileExt == ".JPEG")
{
using (FileStream stream = file.OpenRead())
{
photoes.Add(Image.FromStream(stream));
}
}
}
}
}
.... ...
this.pictureBox1.Image = GetSlidePhoto(photoes, lastPhotoIndex);
----------------------------------

The code can work, but it sucks the memory very much. As you see, this line
of code -
/* photoes.Add(Image.FromStream(stream)); */ 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

Feb 8 '07 #1
4 1966
Hi,

"Mike Chen" <ch****@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
| 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:

Instead of storing the photos store the path to the image, only when you
show a photo the photo is loaded in memory.
--
Ignacio Machin
machin AT laceupsolutions com
Feb 8 '07 #2
Ignacio,
thanks for replying. I test that before my post. If we load the picture
before display it each time, the slide won't run smoothly (The time to new a
image from path flickers). I need to scroll every picture in 0.1 second.

--
Sincerely,
Mike Chen
http://chagel.com
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

"Mike Chen" <ch****@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
| 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:

Instead of storing the photos store the path to the image, only when you
show a photo the photo is loaded in memory.
--
Ignacio Machin
machin AT laceupsolutions com


Feb 8 '07 #3
Why not only load the next image and remove it from memory after its been
displayed. That way you only have the current image and the next image to be
displayed in memory.

-Matthew Newman
-http://www.bestsnowman.com/

"Mike Chen" <ch****@gmail.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
Ignacio,
thanks for replying. I test that before my post. If we load the picture
before display it each time, the slide won't run smoothly (The time to new
a image from path flickers). I need to scroll every picture in 0.1 second.

--
Sincerely,
Mike Chen
http://chagel.com
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
>Hi,

"Mike Chen" <ch****@gmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
| 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:

Instead of storing the photos store the path to the image, only when you
show a photo the photo is loaded in memory.
--
Ignacio Machin
machin AT laceupsolutions com


Feb 8 '07 #4
Hi,

"Mike Chen" <ch****@gmail.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
| Ignacio,
| thanks for replying. I test that before my post. If we load the picture
| before display it each time, the slide won't run smoothly (The time to new
a
| image from path flickers). I need to scroll every picture in 0.1 second.

in 0.1 second ????
You can always load the next one.
Feb 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nick | last post by:
After spending many hours trying to find a simple looking, fast,dynamic php photo-gallery for my digital pictures, I decided to code a my own. Once installed, all you have to do is drop a new...
5
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
5
by: fraser | last post by:
Hi, I have a photo gallery with cat photos here http://mouserspage.cjb.net From the beginning, I have been making each page of thumbnails, with a separate page for each photo, entirely in...
11
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my...
22
by: bevoldjling | last post by:
Hi ! I need some help in putting together a website for our family gathering. Although I'm still pretty "green", I don't think what I need requires terribly advanced skills ...except for one...
0
by: Czechfish | last post by:
How do I change my script to automatically play, rather than clicking through individual slides? What is the action script to skip to a specific slide in the show via a button? (Right now I have...
0
by: Ed Sproull [MSFT] | last post by:
I have an ASP site (www.elsphoto.com} and I have several pages that have slide shows on them. The home page uses JPGs from a directory and the Family, Wedding and Pets pages retrieve the photos...
1
by: Oelie | last post by:
Hello, I'm trying to make a photo slide show in VB6. I'm trying to get the right size for my pictures, they have to fill up the screen entirely. It works with the first picture. But when a picture...
1
by: jrsjrs | last post by:
I have been trying to adapt the photo carousel script located at -- http://www.dynamicdrive.com/dynamicindex14/carousel.htm to open a new page in another frame located directly below the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.