How to create a video background using frames and timer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #31
    Arrays are zero indexed in C#, which means the first item in the array starts from zero.

    So...

    Code:
    string[] strArray = new string[] { "a", "b", "c", "d" };
    strArray[0] == "a"
    strArray[1] == "b"
    ... and so on ...

    So when you start from 1, you're skipping the first iamge. Then when you access the max value, you're out of bounds.

    You need to access from 0 to max value - 1.

    Hope that helps.

    Comment

    • sword117
      New Member
      • Jun 2010
      • 35

      #32
      Originally posted by GaryTexmo
      Arrays are zero indexed in C#, which means the first item in the array starts from zero.

      So...

      Code:
      string[] strArray = new string[] { "a", "b", "c", "d" };
      strArray[0] == "a"
      strArray[1] == "b"
      ... and so on ...

      So when you start from 1, you're skipping the first iamge. Then when you access the max value, you're out of bounds.

      You need to access from 0 to max value - 1.

      Hope that helps.
      is this correct?

      Code:
       
                private void timer1_Tick(object sender, EventArgs e)
              {
      CountFrames++;
       
                  if (CountFrames >= Frames.Length)
                  {
                      CountFrames = 0;
                  }
                  else
                  {
                      Frames[CountFrames] = Image.FromFile(@"Frames\1 (" + CountFrames + ").jpg");
                      this.BackgroundImage = Frames[CountFrames];
                  }
      }

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #33
        You can skip the array entirely now. Just do...

        Code:
        this.BackgroundImage = Image.FromFile(@"Frames\1 (" + (CountFrames + 1).ToString() + ").jpg);
        You need the CountFrames + 1 because I noticed your image files start at 1, not 0.

        I suppose you could also just do the count from 1 to MAX_FRAMES if you're not doing the array ;)

        Comment

        • sword117
          New Member
          • Jun 2010
          • 35

          #34
          Originally posted by GaryTexmo
          You can skip the array entirely now. Just do...

          Code:
          this.BackgroundImage = Image.FromFile(@"Frames\1 (" + (CountFrames + 1).ToString() + ").jpg);
          You need the CountFrames + 1 because I noticed your image files start at 1, not 0.

          I suppose you could also just do the count from 1 to MAX_FRAMES if you're not doing the array ;)
          it worked =) i didnt know that i could use "+(CountFra mes + 1).toString() +". one more thing that i learned lol
          thanks again =)

          Comment

          Working...