Gif Animation running continuously

mduffy

New member
Joined
Mar 25, 2006
Messages
4
Programming Experience
1-3
I read Kulrom's post regarding loading a gif animation in the form load event last night.[FONT=&quot]
The link to the following quote is: http://www.vbdotnetforums.com/showth...=gif+animation[/FONT]
I just did a simple test using an animated GIF file and a picturebox control. I loaded the gif in the Form Load event like so:
PictureBox1.Image = Image.FromFile(Application.StartUpPath & "\myGif.gif")
and it works fine. Maybe, your problem is you are setting the .Image source from Design Mode instead of doing it from Form Load. Try setting the image source in code instead of in the Form Designer and see if that fixes your problem.

I took your advice and placed the image in the picture box when the form loads as quoted above. The problem is I only want to run the animation one time when my application starts instead it runs continually. I created the animation with Jasc Animation shop 3 and set it to run only once.

The gif contains 52 frames of playing cards which fan across the screen in a picture box when the program is compiled and run.

This windows application is my first attempt writing in VB .Net 2003 so I really need some help. I've been doing a lot of searching for a solution to this problem and haven't found a good answer.

Can you give me some code examples how to set the anamation to run one time.

Thanks
mduffy
 
I think it can be resolved very easy ... just find out the time needed for single loop of the animation and then use timer or thread.Sleep(time). Means after animation reach the end time you suppose to unload the animated gif (picBox.Image = nothing) and load a new image static one (take only 1st or last frame of the animated gif). At least it is what i would do if i was in your shoes :)
 
Thank for your reply but could you please give me a more detailed example of how to do what you suggested. I am not a seasoned .net programmer so I need some code that I can use to adapt to my program.

This Gif has a 1 millisecond delay which means it should only take 53 milliseconds to execute all of the frames. The problem is it is taking much longer to paint the images in the picture box than 53 milliseconds and it is running continuously. With a 0 ms delay, I get a Generic GDI+ error and that is why I created the gif with a 1 ms delay for each frame.

I really appreciate any additional help you might provide.

Thanks
mduffy
 
I found a solution to my problem. I used the following code and the gif plays only once in the form load event routine.

Import System.Drawing.Imaging

then use this code:

Dim animatedGif As New Bitmap("Sign.gif")
Dim frameDimension As New FrameDimension(animatedGif.FrameDimensionsList(0))
Dim f As Integer
For f = 0 To animatedGif.GetFrameCount(frameDimension) - 1
animatedGif.SelectActiveFrame(frameDimension, f)
Dim memoryStream As New System.IO.MemoryStream()
animatedGif.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp)
Me.ExamplePictureBox.Image = System.Drawing.Image.FromStream(memoryStream)
Application.DoEvents()
Threading.Thread.CurrentThread.Sleep(100)
Next

Thanks
mduffy
 
I still have one more question. Apparently I actually never see the animation because the animation executes doing the form load. Can you tell me which event I could use to perform the animation after the form gets loaded.

In other words, I want the form to load first then execute the animation so I can actually see the animation.

Thank you for your help and it is really appreciated. Sorry to be such a dummy here.

mduffy
 
Back
Top