473,714 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<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

Feb 8 '07 #1
4 1984
Hi,

"Mike Chen" <ch****@gmail.c omwrote in message
news:%2******** *******@TK2MSFT NGP02.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******** ********@TK2MSF TNGP04.phx.gbl. ..
Hi,

"Mike Chen" <ch****@gmail.c omwrote in message
news:%2******** *******@TK2MSFT NGP02.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.c omwrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
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******** ********@TK2MSF TNGP04.phx.gbl. ..
>Hi,

"Mike Chen" <ch****@gmail.c omwrote in message
news:%2******* ********@TK2MSF TNGP02.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.c omwrote in message
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
| 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
5219
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 folder of images on the server. Dynamic thumbnails, slideshow are built in.
5
3480
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 appeared on my news server, so I'm trying again - this time posting a separate copy of the message to each group. I'm thinking this should be fairly easy to accomplish - a quick and dirty ... what? ... script? program?
5
4311
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 plain html. Since the number of photos I have has increased greatly, it becomes a long and tedious process to go through all the pages to edit the links (to newly added pages) and add in the new pages etc...
11
2132
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 loading procedure there's a point or two where I'll malloc a struct which I then don't need, and dispose of it; I was wondering if there was some way I could optimize this kludge out of existence: void loadContacts () { int fd, bytesread; if (...
22
5119
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 area that has me right baffled. I want to put up a photo album slideshow but I want to stay away from Flash & Javascript. It just seems that anytime I use them, somebody
0
6658
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 a next an previous buttons.) Here is my script: slides_xml = new XML(); slides_xml.onLoad = startSlideShow; slides_xml.load("conferencephotos.xml"); slides_xml.ignoreWhite = true;
0
1568
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 from the database. Each page shows the first slide correctly and the second slide always shows up as a thumbnail. After the show completes once, the second itteration all slides show correctly. I'm using a timer to trigger the slide change and...
1
6118
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 has another resolution it gets the same shape as the picture that was showed before. I've got this so far: Private Sub Form_Load() Timer1.Interval = 1000 Timer1.Enabled = True End Sub
1
2661
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 clickable carousel frame photos. I know that the basic script to do this is as in -- <a href="http://www.example.org/" target="bottom">Click</a> but I cannot figure out how to modify the script from
0
8801
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9015
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.