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. Random Image Generator

Random Image Generator

Scheduled Pinned Locked Moved C#
graphicsdata-structureslounge
11 Posts 7 Posters 2 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.
  • S Offline
    S Offline
    sebogawa
    wrote on last edited by
    #1

    I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

    using System;
    using System.Drawing;
    using System.Windows.Forms;

    namespace Random_Image_Generator
    {
    public partial class mainWindow : Form
    {
    int timeKeeper;
    Bitmap[] images = new Bitmap[30];

        public mainWindow()
        {
            InitializeComponent();
            timer1.Interval = 1000;
            images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
            images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
            images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
            images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
            images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
            images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
            images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
            images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
            images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
            images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
            images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
            images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
            images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
            images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
            images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
            images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
            images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
            images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
            images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
            images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
            images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
            images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
            images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
            images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
            images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
            images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
            images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
            images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
    
    N L D P K 5 Replies Last reply
    0
    • S sebogawa

      I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

      using System;
      using System.Drawing;
      using System.Windows.Forms;

      namespace Random_Image_Generator
      {
      public partial class mainWindow : Form
      {
      int timeKeeper;
      Bitmap[] images = new Bitmap[30];

          public mainWindow()
          {
              InitializeComponent();
              timer1.Interval = 1000;
              images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
              images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
              images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
              images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
              images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
              images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
              images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
              images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
              images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
              images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
              images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
              images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
              images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
              images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
              images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
              images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
              images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
              images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
              images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
              images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
              images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
              images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
              images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
              images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
              images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
              images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
              images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
              images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      List<int> num = new List<int>();

      private void nextImage()
      {
      int randNum = 0;
      do
      {
      randNum = RandomNumber(0, 29);
      }while(num.Contains(randNum));
      num.Add(randNum);
      imageArea.Image = images[randNum];
      }


      I know the language. I've read a book. - _Madmatt

      modified on Monday, March 22, 2010 8:43 PM

      L 1 Reply Last reply
      0
      • S sebogawa

        I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

        using System;
        using System.Drawing;
        using System.Windows.Forms;

        namespace Random_Image_Generator
        {
        public partial class mainWindow : Form
        {
        int timeKeeper;
        Bitmap[] images = new Bitmap[30];

            public mainWindow()
            {
                InitializeComponent();
                timer1.Interval = 1000;
                images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
                images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
                images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
                images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
                images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
                images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
                images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
                images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
                images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
                images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
                images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
                images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
                images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
                images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
                images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
                images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
                images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
                images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
                images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
                images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
                images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
                images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
                images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
                images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
                images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
                images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
                images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
                images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
        
        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, 1.

        sebogawa wrote:

        images[0] = new Bitmap(Bitmap.FromFile("0.bmp")); images[1] = new Bitmap(Bitmap.FromFile("1.bmp")); images[2] = new Bitmap(Bitmap.FromFile("2.bmp")); images[3] = new Bitmap(Bitmap.FromFile("3.bmp")); images[4] = new Bitmap(Bitmap.FromFile("4.bmp")); images[5] = new Bitmap(Bitmap.FromFile("5.bmp")); images[6] = new Bitmap(Bitmap.FromFile("6.bmp")); images[7] = new Bitmap(Bitmap.FromFile("7.bmp")); images[8] = new Bitmap(Bitmap.FromFile("8.bmp")); images[9] = new Bitmap(Bitmap.FromFile("9.bmp")); images[10] = new Bitmap(Bitmap.FromFile("10.bmp")); images[11] = new Bitmap(Bitmap.FromFile("11.bmp")); images[12] = new Bitmap(Bitmap.FromFile("12.bmp")); images[13] = new Bitmap(Bitmap.FromFile("13.bmp")); images[14] = new Bitmap(Bitmap.FromFile("14.bmp")); images[15] = new Bitmap(Bitmap.FromFile("15.bmp")); images[16] = new Bitmap(Bitmap.FromFile("16.bmp")); images[17] = new Bitmap(Bitmap.FromFile("17.bmp")); images[18] = new Bitmap(Bitmap.FromFile("18.bmp")); images[19] = new Bitmap(Bitmap.FromFile("19.bmp")); images[20] = new Bitmap(Bitmap.FromFile("20.bmp")); images[21] = new Bitmap(Bitmap.FromFile("21.bmp")); images[22] = new Bitmap(Bitmap.FromFile("22.bmp")); images[23] = new Bitmap(Bitmap.FromFile("23.bmp")); images[24] = new Bitmap(Bitmap.FromFile("24.bmp")); images[25] = new Bitmap(Bitmap.FromFile("25.bmp")); images[26] = new Bitmap(Bitmap.FromFile("26.bmp")); images[27] = new Bitmap(Bitmap.FromFile("27.bmp")); images[28] = new Bitmap(Bitmap.FromFile("28.bmp")); images[29] = new Bitmap(Bitmap.FromFile("29.bmp"));

        Did you notice some similarity between those lines? Take advantage of it, write a simple 2-line loop that does exactly the same, saving over 1000 characters (and keystrokes?). 2. How would you do it by hand? 3. Hint: forget about arrays, this is another great place for a collection. Look at List<Bitmap> :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


        modified on Monday, March 22, 2010 8:45 PM

        1 Reply Last reply
        0
        • N Not Active

          List<int> num = new List<int>();

          private void nextImage()
          {
          int randNum = 0;
          do
          {
          randNum = RandomNumber(0, 29);
          }while(num.Contains(randNum));
          num.Add(randNum);
          imageArea.Image = images[randNum];
          }


          I know the language. I've read a book. - _Madmatt

          modified on Monday, March 22, 2010 8:43 PM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          It is not completely obvious how that avoids duplicates. ;P I would be inclined to collect images, not numbers; and pick one out of an "available" collection, not stuff them in a "used" collection. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


          N 1 Reply Last reply
          0
          • S sebogawa

            I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

            using System;
            using System.Drawing;
            using System.Windows.Forms;

            namespace Random_Image_Generator
            {
            public partial class mainWindow : Form
            {
            int timeKeeper;
            Bitmap[] images = new Bitmap[30];

                public mainWindow()
                {
                    InitializeComponent();
                    timer1.Interval = 1000;
                    images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
                    images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
                    images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
                    images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
                    images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
                    images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
                    images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
                    images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
                    images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
                    images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
                    images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
                    images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
                    images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
                    images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
                    images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
                    images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
                    images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
                    images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
                    images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
                    images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
                    images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
                    images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
                    images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
                    images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
                    images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
                    images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
                    images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
                    images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
            
            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            How about loading your images into a List<Bitmap>. Apply a random Sort algorithm, then create a Queue<Bitmap> from the list. Now you can just dequeue each image as you display it.

            Dave
            Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            1 Reply Last reply
            0
            • L Luc Pattyn

              It is not completely obvious how that avoids duplicates. ;P I would be inclined to collect images, not numbers; and pick one out of an "available" collection, not stuff them in a "used" collection. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Not the best, but neither was the original code ;P I agree that a lot of duplicate typing could have been avoided.


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              • S sebogawa

                I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

                using System;
                using System.Drawing;
                using System.Windows.Forms;

                namespace Random_Image_Generator
                {
                public partial class mainWindow : Form
                {
                int timeKeeper;
                Bitmap[] images = new Bitmap[30];

                    public mainWindow()
                    {
                        InitializeComponent();
                        timer1.Interval = 1000;
                        images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
                        images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
                        images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
                        images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
                        images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
                        images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
                        images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
                        images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
                        images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
                        images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
                        images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
                        images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
                        images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
                        images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
                        images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
                        images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
                        images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
                        images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
                        images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
                        images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
                        images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
                        images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
                        images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
                        images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
                        images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
                        images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
                        images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
                        images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
                
                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Use a List, pick a random index (0 to Count-1 ), display and remove that image, repeat until empty.

                L 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Use a List, pick a random index (0 to Count-1 ), display and remove that image, repeat until empty.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Yes, and while we're at it: Why load all these bitmaps in advance at all? I would only load the one currently selected for display. For selection an array of filenames will suffice. This will go a little easier on the memory. With 30 bitmaps this may not appear important, but still it is a waste of memory. Ans when one day the program is expanded to support 300 bitmaps (or 30000, 3000000 ...) you will get to see something I have not seen since the days of the old C64: An out of memory exception.

                  A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

                  1 Reply Last reply
                  0
                  • S sebogawa

                    I am working on a project that takes 30 images from file, stuffs them in an array and displays them sequentially in a random order. There is a 30 second delay between each image, like a slide show, and no image can be displayed more than once. I got everthing down except for the dont display the same image twice and the end the sequence once every image was displayed. Here is my code.

                    using System;
                    using System.Drawing;
                    using System.Windows.Forms;

                    namespace Random_Image_Generator
                    {
                    public partial class mainWindow : Form
                    {
                    int timeKeeper;
                    Bitmap[] images = new Bitmap[30];

                        public mainWindow()
                        {
                            InitializeComponent();
                            timer1.Interval = 1000;
                            images\[0\] = new Bitmap(Bitmap.FromFile("0.bmp"));
                            images\[1\] = new Bitmap(Bitmap.FromFile("1.bmp"));
                            images\[2\] = new Bitmap(Bitmap.FromFile("2.bmp"));
                            images\[3\] = new Bitmap(Bitmap.FromFile("3.bmp"));
                            images\[4\] = new Bitmap(Bitmap.FromFile("4.bmp"));
                            images\[5\] = new Bitmap(Bitmap.FromFile("5.bmp"));
                            images\[6\] = new Bitmap(Bitmap.FromFile("6.bmp"));
                            images\[7\] = new Bitmap(Bitmap.FromFile("7.bmp"));
                            images\[8\] = new Bitmap(Bitmap.FromFile("8.bmp"));
                            images\[9\] = new Bitmap(Bitmap.FromFile("9.bmp"));
                            images\[10\] = new Bitmap(Bitmap.FromFile("10.bmp"));
                            images\[11\] = new Bitmap(Bitmap.FromFile("11.bmp"));
                            images\[12\] = new Bitmap(Bitmap.FromFile("12.bmp"));
                            images\[13\] = new Bitmap(Bitmap.FromFile("13.bmp"));
                            images\[14\] = new Bitmap(Bitmap.FromFile("14.bmp"));
                            images\[15\] = new Bitmap(Bitmap.FromFile("15.bmp"));
                            images\[16\] = new Bitmap(Bitmap.FromFile("16.bmp"));
                            images\[17\] = new Bitmap(Bitmap.FromFile("17.bmp"));
                            images\[18\] = new Bitmap(Bitmap.FromFile("18.bmp"));
                            images\[19\] = new Bitmap(Bitmap.FromFile("19.bmp"));
                            images\[20\] = new Bitmap(Bitmap.FromFile("20.bmp"));
                            images\[21\] = new Bitmap(Bitmap.FromFile("21.bmp"));
                            images\[22\] = new Bitmap(Bitmap.FromFile("22.bmp"));
                            images\[23\] = new Bitmap(Bitmap.FromFile("23.bmp"));
                            images\[24\] = new Bitmap(Bitmap.FromFile("24.bmp"));
                            images\[25\] = new Bitmap(Bitmap.FromFile("25.bmp"));
                            images\[26\] = new Bitmap(Bitmap.FromFile("26.bmp"));
                            images\[27\] = new Bitmap(Bitmap.FromFile("27.bmp"))
                    
                    K Offline
                    K Offline
                    koleraba
                    wrote on last edited by
                    #9

                    Hi I would try the following approach. Create the class in which you store the bitmap and a boolean field, which tells you if the image was already shown:

                    public class ImageItem
                    {
                    private Bitmap _image;
                    public bool Shown{get;set;}

                    public ImageItem(Bitmap image)
                    {
                        \_image = image;
                        Shown = false;
                    }
                    

                    }

                    private void timer1_Tick(object sender, EventArgs e)
                    {
                    if(images.Any(image => image.Shown == false))
                    {
                    nextImage()
                    }
                    //You shown all the images
                    else
                    {
                    //quit.
                    }
                    }

                    private void nextImage(Bitmap image)
                    {
                    int randNumber;
                    do
                    {
                    randNumber = RandomNumber(0, 29);
                    }while(images[randNumber].Shown != false)
                    images[randNumber].Shown = true;
                    imageArea.Image = images[randNumber];
                    }

                    I typed the code directly to the page(without visual studio) so I hope I didn't make any typos. Uros

                    N 1 Reply Last reply
                    0
                    • K koleraba

                      Hi I would try the following approach. Create the class in which you store the bitmap and a boolean field, which tells you if the image was already shown:

                      public class ImageItem
                      {
                      private Bitmap _image;
                      public bool Shown{get;set;}

                      public ImageItem(Bitmap image)
                      {
                          \_image = image;
                          Shown = false;
                      }
                      

                      }

                      private void timer1_Tick(object sender, EventArgs e)
                      {
                      if(images.Any(image => image.Shown == false))
                      {
                      nextImage()
                      }
                      //You shown all the images
                      else
                      {
                      //quit.
                      }
                      }

                      private void nextImage(Bitmap image)
                      {
                      int randNumber;
                      do
                      {
                      randNumber = RandomNumber(0, 29);
                      }while(images[randNumber].Shown != false)
                      images[randNumber].Shown = true;
                      imageArea.Image = images[randNumber];
                      }

                      I typed the code directly to the page(without visual studio) so I hope I didn't make any typos. Uros

                      N Offline
                      N Offline
                      Not Active
                      wrote on last edited by
                      #10

                      So 12 hours later you other responses and pass it off as your own X|


                      I know the language. I've read a book. - _Madmatt

                      K 1 Reply Last reply
                      0
                      • N Not Active

                        So 12 hours later you other responses and pass it off as your own X|


                        I know the language. I've read a book. - _Madmatt

                        K Offline
                        K Offline
                        koleraba
                        wrote on last edited by
                        #11

                        Hey sorry I didn't even know that is a bad thing. I just saw a question and offered to help.

                        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