image slideshow by extracting images from a specified directory
-
i am getting image based slideshow by using image list and picture box. i want it to make it more dynamic and flexible... I tried using "System.IO.Directory.GetFiles("C://MyPictures")"......So tat image files (after specifying the extension also ("*.jpeg"))can be extracted from the directory and be displayed as slideshow.....But its kinda not working out for me....need help !!! ************************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 3000; timer1.Enabled = true; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { System.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images"); System.IO.FileInfo[] files=dirInfo.GetFiles("*.jpeg"); if(files!=null) { foreach(System.IO.FileInfo file in files) { pictureBox1.Image=Image.FromFile(file); } } } } }
-
i am getting image based slideshow by using image list and picture box. i want it to make it more dynamic and flexible... I tried using "System.IO.Directory.GetFiles("C://MyPictures")"......So tat image files (after specifying the extension also ("*.jpeg"))can be extracted from the directory and be displayed as slideshow.....But its kinda not working out for me....need help !!! ************************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 3000; timer1.Enabled = true; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { System.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images"); System.IO.FileInfo[] files=dirInfo.GetFiles("*.jpeg"); if(files!=null) { foreach(System.IO.FileInfo file in files) { pictureBox1.Image=Image.FromFile(file); } } } } }
Hi, Do you get a sepcific error message during comilation/runtime? Try to use
pictureBox1.Image = Image.FromFile(file.FullName);
FromFile accepts only the filename, not the FileInfo. Regards SebastianIt's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
i am getting image based slideshow by using image list and picture box. i want it to make it more dynamic and flexible... I tried using "System.IO.Directory.GetFiles("C://MyPictures")"......So tat image files (after specifying the extension also ("*.jpeg"))can be extracted from the directory and be displayed as slideshow.....But its kinda not working out for me....need help !!! ************************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 3000; timer1.Enabled = true; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { System.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images"); System.IO.FileInfo[] files=dirInfo.GetFiles("*.jpeg"); if(files!=null) { foreach(System.IO.FileInfo file in files) { pictureBox1.Image=Image.FromFile(file); } } } } }
The most obvious thing here is that by putting all of the file fetching code inside the
ontick
handler, each time it fires, it gets all the files again and shows the first one every time (I think). My suggestion, moveSystem.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images");
files=dirInfo.GetFiles("*.jpeg");into Form_Load(), or other suitable place. create
System.IO.FileInfo[] files = null;
as a field of the form. add an index fieldint index = 0;
as well. Then in yourontick
handlerif (files != null) { if (index >= files.Length) { timer1.Enabled = false; } else { pictureBox1.Image=Image.FromFile(files\[index++\]); pictureBox1.Image=Image.FromFile(files\[index++\].FullName); } }
[MOD] Realized I had forgotten the '.FullName' property [/MOD]
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
modified on Thursday, March 26, 2009 4:49 PM
-
The most obvious thing here is that by putting all of the file fetching code inside the
ontick
handler, each time it fires, it gets all the files again and shows the first one every time (I think). My suggestion, moveSystem.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images");
files=dirInfo.GetFiles("*.jpeg");into Form_Load(), or other suitable place. create
System.IO.FileInfo[] files = null;
as a field of the form. add an index fieldint index = 0;
as well. Then in yourontick
handlerif (files != null) { if (index >= files.Length) { timer1.Enabled = false; } else { pictureBox1.Image=Image.FromFile(files\[index++\]); pictureBox1.Image=Image.FromFile(files\[index++\].FullName); } }
[MOD] Realized I had forgotten the '.FullName' property [/MOD]
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
modified on Thursday, March 26, 2009 4:49 PM
dude d slideshow stops after d last image is read !!! i want d slideshow to run continously .....plz help !!
-
The most obvious thing here is that by putting all of the file fetching code inside the
ontick
handler, each time it fires, it gets all the files again and shows the first one every time (I think). My suggestion, moveSystem.IO.DirectoryInfo dirInfo=new System.IO.DirectoryInfo("C://Images");
files=dirInfo.GetFiles("*.jpeg");into Form_Load(), or other suitable place. create
System.IO.FileInfo[] files = null;
as a field of the form. add an index fieldint index = 0;
as well. Then in yourontick
handlerif (files != null) { if (index >= files.Length) { timer1.Enabled = false; } else { pictureBox1.Image=Image.FromFile(files\[index++\]); pictureBox1.Image=Image.FromFile(files\[index++\].FullName); } }
[MOD] Realized I had forgotten the '.FullName' property [/MOD]
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
modified on Thursday, March 26, 2009 4:49 PM
i want d slideshow to execute continously in a repeated fashion and not stop after reading the last image. Is there any way i can do it ??
-
i want d slideshow to execute continously in a repeated fashion and not stop after reading the last image. Is there any way i can do it ??
OK. It's hard to be certain without seeing your code, but something like this should work. Change the code of the
ontick
handler so it looks something like this:if (files != null)
{
if (index >= files.Length)
{
timer1.Enabled = false;
index = 0;
}
else
{
pictureBox1.Image=Image.FromFile(files[index++].FullName);
}
}All that this does, is detect when the last image has been used and resets the index back to the start. Hope this helps. :)
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”