Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. image slideshow by extracting images from a specified directory

image slideshow by extracting images from a specified directory

Scheduled Pinned Locked Moved C#
graphicshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mist_psycho
    wrote on last edited by
    #1

    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); } } } } }

    S H 2 Replies Last reply
    0
    • M mist_psycho

      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); } } } } }

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      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 Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      1 Reply Last reply
      0
      • M mist_psycho

        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); } } } } }

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

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

        System.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 field int index = 0; as well. Then in your ontick handler

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

        M 2 Replies Last reply
        0
        • H Henry Minute

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

          System.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 field int index = 0; as well. Then in your ontick handler

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

          M Offline
          M Offline
          mist_psycho
          wrote on last edited by
          #4

          dude d slideshow stops after d last image is read !!! i want d slideshow to run continously .....plz help !!

          1 Reply Last reply
          0
          • H Henry Minute

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

            System.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 field int index = 0; as well. Then in your ontick handler

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

            M Offline
            M Offline
            mist_psycho
            wrote on last edited by
            #5

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

            H 1 Reply Last reply
            0
            • M mist_psycho

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

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups