-
Aug 28th, 2010, 05:55 AM
#1
Thread Starter
Junior Member
Loop Once Through an Animated GIF
I'm using a picture box to show an animated gif on my form. When i created the gif, I set it so it only loops once. The gif plays correctly in a browser, but when i set the image of the picture box to my animated gif it continuously loops.
I only want to loop once through the images embedded in my animated gif when i set the image of the picture box. What is the easiest way to do this? Does anyone have or know of any sample code to do this? I have been searching this for a while, but have not been able to find anything.
Thanks in advance.
-
Aug 28th, 2010, 06:40 AM
#2
Re: Loop Once Through an Animated GIF
Try the ImageAnimator class.
-
Aug 28th, 2010, 08:06 AM
#3
Re: Loop Once Through an Animated GIF
ImageAnimator unfortunately doesn't have a convenient "play once" method. Maybe it's not the most elegant solution, but I found this works:
vb.net Code:
Private GIFAnim As Image = Image.FromFile(--your animated GIF file--)
Private frames As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frames = GIFAnim.GetFrameCount(Imaging.FrameDimension.Time)
ImageAnimator.Animate(GIFAnim, AddressOf paintFrame)
End Sub
Private Sub paintFrame(ByVal sender As Object, ByVal e As EventArgs)
If frames > 0 Then PictureBox1.Invalidate() Else ImageAnimator.StopAnimate(GIFAnim, AddressOf StopAnim)
End Sub
Private Sub StopAnim(ByVal sender As Object, ByVal e As EventArgs)
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If frames > 0 Then
ImageAnimator.UpdateFrames()
e.Graphics.DrawImage(GIFAnim, Point.Empty)
frames -= 1
End If
End Sub
BB
-
Oct 3rd, 2010, 11:15 AM
#4
Thread Starter
Junior Member
Re: Loop Once Through an Animated GIF
Sorry, I missed this response. I will give it a try. Thanks much.
-
Oct 3rd, 2010, 11:45 AM
#5
Thread Starter
Junior Member
Re: Loop Once Through an Animated GIF
That works great. The only problem is it freezes the image at the 1st frame as opposed to the 3rd frame. But I should be able to figure that out.
-
Sep 19th, 2013, 12:14 PM
#6
New Member
Re: Loop Once Through an Animated GIF
hi boobs boobs, I am an absolute newbie!
I am using Visual Basic 2010 Express.
I wrote a tiny program that only plays a gif-animation and a background sound. Of course, I have the same problem that the animation is set to loop.
My code:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
My.Computer.Audio.Play(My.Resources.sound_1, AudioPlayMode.Background)
End Sub
End Class
I have tested your code - it works without problems.
But I have the problem to integrate it into my project (or conversely), because I don't have the know how..
Please help me:
I want, as possible, the animation and .wav load from a resource (integrated in .exe after compile). On startup the animation should run without click button (no button).
thanks Tom
-
Sep 19th, 2013, 03:15 PM
#7
Re: Loop Once Through an Animated GIF
You can load and run the Gif from Resources without any difficulty. Simply replace GIFAnim with the reference to your resource Gif wherever it appears. To run the animation unprompted move all the code in the Button1.Click handler to a Form1.Shown handler.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Sep 20th, 2013, 07:08 AM
#8
New Member
Re: Loop Once Through an Animated GIF
Thank you, but I'm to stupid.
My code now:
I don't know how I can change the code for use the Gif from Resource and what I can do for center the image in the form and in the PictureBox?
I try alot but - what I write in the first line!
Please Help...
-
Feb 19th, 2014, 08:50 AM
#9
New Member
Re: Loop Once Through an Animated GIF
Hi There, You got working how to use Gif from Resource ? Im stucked at this point too, i really appreciate your answer. Im waiting if u can help me
Originally Posted by Tom_Berlin
Thank you, but I'm to stupid.
My code now:
I don't know how I can change the code for use the Gif from Resource and what I can do for center the image in the form and in the PictureBox?
I try alot but - what I write in the first line!
Please Help...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|