468,316 Members | 1,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Problem with Animated GIFs

I thought it would be nice to display some animated GIFs on some of my
forms. I put a PictureBox control on a form, and loaded my GIF file in. It
animates, but not properly. It seems very jerky and dwells on some frames
longer than it should. Searching for this problem, I have found several
people who have stated that animated GIFs don't work in a PictureBox at all,
and you have to use the ImageAnimator. I assume they must be referring to an
older version, because I do get some animation, it's just not quite right. I
am using VB2005 Express.
I thought it might be a problem with running under the IDE, but I still get
the same problem if I build the project and run the release exe.
I looked up ImageAnimator in the help, and it is not especially helpful, but
there was some sample code. I tried this, and I get exactly the same
problem. The image displays and animates, but the timing seems all wrong. If
I use the image preview in Windows XP the image displays fine, so I don't
think it's a problem with the GIF file itself.
Any suggestions, greatly appreciated.
TIA
Phil.
Aug 13 '07 #1
27 12514
Phil,

You are sure that you set the properties of the picturebox right

By instance this ones let it look on every screen different

http://msdn2.microsoft.com/en-us/lib....sizemode.aspx

Cor

"Phil" <N/Aschreef in bericht news:13*************@corp.supernews.com...
>I thought it would be nice to display some animated GIFs on some of my
forms. I put a PictureBox control on a form, and loaded my GIF file in. It
animates, but not properly. It seems very jerky and dwells on some frames
longer than it should. Searching for this problem, I have found several
people who have stated that animated GIFs don't work in a PictureBox at
all, and you have to use the ImageAnimator. I assume they must be referring
to an older version, because I do get some animation, it's just not quite
right. I am using VB2005 Express.
I thought it might be a problem with running under the IDE, but I still
get the same problem if I build the project and run the release exe.
I looked up ImageAnimator in the help, and it is not especially helpful,
but there was some sample code. I tried this, and I get exactly the same
problem. The image displays and animates, but the timing seems all wrong.
If I use the image preview in Windows XP the image displays fine, so I
don't think it's a problem with the GIF file itself.
Any suggestions, greatly appreciated.
TIA
Phil.
Aug 13 '07 #2
Hi Phil,

Based on my understanding, you'd like to display some animated GIFs on some
of your forms. But you find that the animated GIF is slower when it is
displayed in a WinForm than in the image preview in the Windows Explorer.
If I'm off base, please feel free to let me know.

I performed some tests and did reproduce the problem. When I display an
animated GIF in a PictureBox on a WinForm, the animation is a little slower
than displayed in the Internet Explorer.

I guess WinForm limits the maximum frames displayed per second. I have
seached in our inner database, but unfortunately, I haven't found any
information about it so far.

I will consult this issue in our inner discussion group and as soon as I
get any news, I will get it back to you.

In addtion, although my animated GIF is displayed slower in a WinForm, but
the animation is smooth. As you have mentioned, the animated GIF you're
using seems jerky when it is display in a form. Could you please send me
the animated GIF? To get my actual email address, remove 'online' from my
displayed email address.

Thank you for your cooperation and patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 14 '07 #3

You are sure that you set the properties of the picturebox right

By instance this ones let it look on every screen different

http://msdn2.microsoft.com/en-us/lib....sizemode.aspx
I set SizeMode to AutoSize, but I'll try setting the size manually and see
if that makes any difference.
That wouldn't explain the problem when using ImageAnimator though, as in
that example it was drawing directly on the form.
Aug 14 '07 #4
>You are sure that you set the properties of the picturebox right
>>
By instance this ones let it look on every screen different

http://msdn2.microsoft.com/en-us/lib....sizemode.aspx
I set SizeMode to AutoSize, but I'll try setting the size manually and see
if that makes any difference.
I tried setting SizeMode to Normal, and it makes no difference.
Aug 14 '07 #5
Within the IDE or when running the program?
It makes no difference whether I run the program from within the IDE or
compile it, and run the exe.
In the IDE, I don't see any
animation at all.
I don't see any animation when using the form designer. That is not a
problem. I am only concerned with the runtime behaviour.
When running the program, it is displayed correctly.
Not for me :(
>(VB 2005 Express)
That is what I am using too.


Aug 14 '07 #6
"Phil" <N/Aschrieb
>
Within the IDE or when running the program?

It makes no difference whether I run the program from within the IDE
or compile it, and run the exe.
In the IDE, I don't see any
animation at all.

I don't see any animation when using the form designer. That is not
a problem. I am only concerned with the runtime behaviour.
When running the program, it is displayed correctly.

Not for me :(
(VB 2005 Express)

That is what I am using too.

What else does the application do? Does it do any other job while you are
watching the image? Maybe you are using System.Windows.Forms.Timer that does
things from time to time?

Have you already tried it in a new project?
Armin

Aug 14 '07 #7
What else does the application do?
Nothing yet. First thing I tried when it didn't work was to create a new
project to ensure nothing else might be interfering.

Aug 14 '07 #8
I tried calling UpdateFrames twice in my Paint event handler, and now it
is displaying the new frame correctly.
Actually that seemed to work once, but is now not working again. :-(
Aug 14 '07 #9

"Phil" <N/Awrote in message news:13*************@corp.supernews.com...
>I tried calling UpdateFrames twice in my Paint event handler, and now it
is displaying the new frame correctly.

Actually that seemed to work once, but is now not working again. :-(
What does seem to fix it though is calling
Threading.Thread.Sleep(10)

before calling UpdateFrames.
Aug 14 '07 #10

"Phil" <N/Awrote in message news:13*************@corp.supernews.com...
>I thought it would be nice to display some animated GIFs on some of my
forms. I put a PictureBox control on a form, and loaded my GIF file in. It
animates, but not properly. It seems very jerky and dwells on some frames
longer than it should. Searching for this problem, I have found several
people who have stated that animated GIFs don't work in a PictureBox at
all, and you have to use the ImageAnimator. I assume they must be referring
to an older version, because I do get some animation, it's just not quite
right. I am using VB2005 Express.
I thought it might be a problem with running under the IDE, but I still
get the same problem if I build the project and run the release exe.
I looked up ImageAnimator in the help, and it is not especially helpful,
but there was some sample code. I tried this, and I get exactly the same
problem. The image displays and animates, but the timing seems all wrong.
If I use the image preview in Windows XP the image displays fine, so I
don't think it's a problem with the GIF file itself.
Any suggestions, greatly appreciated.
TIA
Phil.
It seems this may be a known problem.
I found this article
http://visualbasic.about.com/od/usingvbnet/a/GDIP10.htm
which says:
"... the ImageAnimator class in .NET doesn't handle timing the display of
the individual images very well. GDI+ uses the event processing provided by
Windows Forms and the Windows message pump. That's just not good enough to
keep the animation from being jumpy and even skip frames entirely. "
Aug 14 '07 #11
On Aug 13, 9:41 am, "Phil" <N/Awrote:
I thought it would be nice to display some animated GIFs on some of my
forms. I put a PictureBox control on a form, and loaded my GIF file in. It
animates, but not properly. It seems very jerky and dwells on some frames
longer than it should. Searching for this problem, I have found several
people who have stated that animated GIFs don't work in a PictureBox at all,
and you have to use the ImageAnimator. I assume they must be referring to an
older version, because I do get some animation, it's just not quite right. I
am using VB2005 Express.
I thought it might be a problem with running under the IDE, but I still get
the same problem if I build the project and run the release exe.
I looked up ImageAnimator in the help, and it is not especially helpful, but
there was some sample code. I tried this, and I get exactly the same
problem. The image displays and animates, but the timing seems all wrong. If
I use the image preview in Windows XP the image displays fine, so I don't
think it's a problem with the GIF file itself.
Any suggestions, greatly appreciated.
TIA
Phil.
Hi,
Can you use AxAnimation in Express? It would be in the Tools/Choose
ToolBox items, and select the Com tab.
Thats what I am currently using. Also, there is a project in Code
Project named .NET Animation Control that you can add, I have tried
that also and it works. I do use .avi files though.
Jeff

Aug 14 '07 #12
Hi,
Can you use AxAnimation in Express? It would be in the Tools/Choose
ToolBox items, and select the Com tab.
I have AXBrowse.AXBrowser but not AXAnimation.
Presumably this is something that is part of some other application and
needs to be installed separately.
Thats what I am currently using. Also, there is a project in Code
Project named .NET Animation Control that you can add, I have tried
that also and it works. I do use .avi files though.
I would like to be able to use AVI files too, so I may check that out.

Thanks,
Phil.
Aug 15 '07 #13
What does seem to fix it though is calling
Threading.Thread.Sleep(10)

before calling UpdateFrames.
It might seem odd that adding a delay should prevent the animation from
skipping frames, but this could be explained if there is a rounding error in
the handling of time in ImageAnimator.

I would guess that the way it works is that the Animate method stores the
current time, and then sets up a timer to trigger the FrameChange event.
Each time the FrameChanged event is fired, it would update the stored time,
and set a new timer for the next frame.
If the precision of the variable used to store this time and the precision
of the variable used to store the timer interval are different, it is
possible either for the event to be raised slightly too early or for
UpdateFrames to think it is not yet time for the next frame.

If someone from Microsoft is reading, perhaps they could get someone to look
at the code for ImageAnimator, to see if this might be what's happening. If
so, it should be a simple fix, to make it round up instead of down where the
rounding is occuring.

What puzzles me though is that putting a delay in the Paint event handler
before calling UpdateFrames fixes the problem, but putting the delay in the
FrameChanged event handler before calling Invalidate does not work.
Aug 15 '07 #14
>Also, there is a project in Code
Project named .NET Animation Control that you can add, I have tried
that also and it works. I do use .avi files though.

I would like to be able to use AVI files too, so I may check that out.
I found this. It is called CGAnimation, and is written in C#. I loaded into
C# and I got a message that it was written for an older version of visual
studio. It seemed to convert it OK, and I was able to build the DLL.
I added this to my toolbox in VB, and was able to get it working, although
I've found a couple of problems with it. Firstly it doesn't display properly
in the designer. This isn't a major problem, but is annoying. Secondly the
Transparent property does not seem to work correctly. It will correctly use
the form's background colour, but if the form has a background image, it
does not display it correctly.
Also, it seems OK with an AVI, but does not seem to work with an animated
GIF. This may be by design, I'm not sure.
Does anyone have any experience using this control? Is it worth trying to
convert this to VB and trying to debug it, or is there a better way of
displaying AVI files?

Thanks,
Phil.
Aug 15 '07 #15
Try this:
control panel -display: Folder "settings", button "advanced", folder
"problem...", reduce hardware acceleration to minimum. Accept.

(maybe text's slightly differ; I don't have the English OS version)

Does it make a difference?
Armin

Aug 15 '07 #16

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Try this:
control panel -display: Folder "settings", button "advanced", folder
"problem...", reduce hardware acceleration to minimum. Accept.

(maybe text's slightly differ; I don't have the English OS version)
Control PanelDisplaySettingsAdvancedTroubleshooting
>
Does it make a difference?
No. I set the acceleration to None, but it makes no difference.
Aug 15 '07 #17
"Phil" <N/Aschrieb
>
"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Try this:
control panel -display: Folder "settings", button "advanced",
folder "problem...", reduce hardware acceleration to minimum.
Accept.

(maybe text's slightly differ; I don't have the English OS
version)

Control PanelDisplaySettingsAdvancedTroubleshooting

Does it make a difference?

No. I set the acceleration to None, but it makes no difference.
Hmmm.. Another attempt: Add a Timer (system.windows.forms.timer), set
interval to 10. In it's tick event, call ThePicturebox.Refresh. Any
difference?

Try booting in safe mode. Difference?
Armin

Aug 15 '07 #18
On Aug 15, 3:13 am, "Phil" <N/Awrote:
Hi,
Can you use AxAnimation in Express? It would be in the Tools/Choose
ToolBox items, and select the Com tab.

I have AXBrowse.AXBrowser but not AXAnimation.
Presumably this is something that is part of some other application and
needs to be installed separately.
Thats what I am currently using. Also, there is a project in Code
Project named .NET Animation Control that you can add, I have tried
that also and it works. I do use .avi files though.

I would like to be able to use AVI files too, so I may check that out.

Thanks,
Phil.
Hi,
In the ToolBox items, click the com tab and look for an item that you
can named,
Microsoft Animation Control 6.0(SP4). Placing that on your form will
allow you to run
animations. If you do not see that, click the browse and go to Windows/
System32
and look for a dll named mscomctl2, something like that, and adding it
should give the amination
control.
Jeff

Aug 15 '07 #19
Hi Phil,

Sorry for my delayed reply!

You have mentioned that you found a workaround to use WebBrowser to display
the animated GIFs on a form. But the problems of this workaround are that
it's difficult to change the back ground color of the WebBrowser control
and load the animated GIFs from the application resources.

I have done some research on these two problems, but unfortunately I didn't
find a solution for them.

In fact, animated GIF has stored timing interval information of each frame
in the GIF file itself. We can retrieve it through the PropertyItems
property of the Image class. Once we get this information, we could use a
System.Windows.Forms.Timer component to control and display the animated
GIF. The following is a sample, which requires you add a PictureBox on the
form.

Imports System.Drawing.Imaging
Imports System.IO

Public Class Form1

Dim gif As Image = Image.FromFile(Application.StartupPath &
"\test1.gif")

Dim fcount As Integer = gif.GetFrameCount(FrameDimension.Time)
Dim interval(fcount) As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim item As PropertyItem = gif.GetPropertyItem(20736)
Dim index As Integer = 0

For i As Integer = 0 To gif.GetFrameCount(FrameDimension.Time) - 1
interval(i) = BitConverter.ToInt32(item.Value, index)
index += 4
Next
ShowGif()
' the timing interval storted in the GIF file is of the unit of
centi-second
Me.Timer1.Interval = interval(findex) * 10
Me.Timer1.Start()
End Sub

Dim findex As Integer = 0
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
findex += 1
If (findex = fcount) Then
findex = 0
End If

ShowGif()
Me.Timer1.Interval = interval(findex) * 10

End Sub

Private Sub ShowGif()
gif.SelectActiveFrame(FrameDimension.Time, findex)
Me.PictureBox1.Invalidate()

End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(gif, New Point(0, 0))
End Sub
End Class

I display the GIF you provided using the above code and the animation on
the PictureBox is not slower than it is in IE.

Please try my sample code out on your side and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support

Aug 20 '07 #20
Thanks Linda, I'll give this a try and let you know if it helps.
Cheers,
Phil.

"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:av**************@TK2MSFTNGHUB02.phx.gbl...
Hi Phil,

Sorry for my delayed reply!

You have mentioned that you found a workaround to use WebBrowser to
display
the animated GIFs on a form. But the problems of this workaround are that
it's difficult to change the back ground color of the WebBrowser control
and load the animated GIFs from the application resources.

I have done some research on these two problems, but unfortunately I
didn't
find a solution for them.

In fact, animated GIF has stored timing interval information of each frame
in the GIF file itself. We can retrieve it through the PropertyItems
property of the Image class. Once we get this information, we could use a
System.Windows.Forms.Timer component to control and display the animated
GIF. The following is a sample, which requires you add a PictureBox on the
form.

Imports System.Drawing.Imaging
Imports System.IO

Public Class Form1

Dim gif As Image = Image.FromFile(Application.StartupPath &
"\test1.gif")

Dim fcount As Integer = gif.GetFrameCount(FrameDimension.Time)
Dim interval(fcount) As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim item As PropertyItem = gif.GetPropertyItem(20736)
Dim index As Integer = 0

For i As Integer = 0 To gif.GetFrameCount(FrameDimension.Time) - 1
interval(i) = BitConverter.ToInt32(item.Value, index)
index += 4
Next
ShowGif()
' the timing interval storted in the GIF file is of the unit of
centi-second
Me.Timer1.Interval = interval(findex) * 10
Me.Timer1.Start()
End Sub

Dim findex As Integer = 0
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
findex += 1
If (findex = fcount) Then
findex = 0
End If

ShowGif()
Me.Timer1.Interval = interval(findex) * 10

End Sub

Private Sub ShowGif()
gif.SelectActiveFrame(FrameDimension.Time, findex)
Me.PictureBox1.Invalidate()

End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(gif, New Point(0, 0))
End Sub
End Class

I display the GIF you provided using the above code and the animation on
the PictureBox is not slower than it is in IE.

Please try my sample code out on your side and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support

Aug 22 '07 #21
Hi Phil,

Have you tried my sample code out? How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Aug 24 '07 #22
>
Have you tried my sample code out?
Sorry, I have been away.
How about the problem now?
Yes, your code works very well The animated GIF displays correctly.

I added a second picture box and loaded the same image in normally, and it
is very clear that the default code in the picturebox control itself is
displaying the animation too slowly and is missing out frames. This would
definitely therefore appear to be a bug in the picturebox control, although
it is puzzling why other people don't see the same problem. I guess it must
be something to do with my hardware. If you'd like any extra information
about my PC set-up to help track down the error, please let me know.

Meanwhile I'll have a go at building your code into a new custom control,
that I can use in place of the picturebox whenever I need to display an
animated GIF.

Thanks,
Phil.

Aug 28 '07 #23
Hi Phil,

Thank you for your feedback! I am glad to hear that my code works on your
side.

I think also the problem may be specific to your hardware. You may have a
try on another PC to see if the problem still exists.

If convenience, please send me the information about your PC set-up and I
will record it in our internal database. It will definitely help to improve
our product. (To get my actual email, remove 'online' from my displayed
email address.)

We appreciate your contribution to our product!

Sincerely,
Linda Liu
Microsoft Online Community Support

Aug 30 '07 #24
>
If convenience, please send me the information about your PC set-up and I
will record it in our internal database. It will definitely help to
improve
our product. (To get my actual email, remove 'online' from my displayed
email address.)
System:
Microsoft Windows XP
Professional
Version 2002
Service Pack 2

Computer:
AMD Sempron(tm) Processor
3000+
1.81 GHz, 512 MB of RAM
Physical Address Extension

Display Adapter:
WinFast PX6200 TC

Monitor:
Ergovision 975TCO95

Display Properties
Screen resolution 128x1024
Color quality Highest (32 bit)
Advanced:
Normal size (96 DPI)
Screen refresh rate 85 Hertz
There is also a GeForce 6200 TurboCache tab which displays further nVidia
settings. I'm not sure if any of these may be relevant.

HTH
Phil.
Aug 31 '07 #25
Screen resolution 128x1024

Wow, that must be one narrow monitor.

:-)

Thanks,

Seth Rowe

Aug 31 '07 #26

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@l22g2000prc.googlegr oups.com...
>Screen resolution 128x1024

Wow, that must be one narrow monitor.
oops, should have been 1280 not 128 :-)
Sep 3 '07 #27
Hi Phil,

Thank you for your reply!

I will record this information in our inner database.

If you have any other question in the future, please don't hesitate to
contact us. It's our pleasure to be of assistance!

Have a nice day!

Sincerely,
Linda Liu
Microsoft Online Community Support

Sep 5 '07 #28

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by MrPickwick | last post: by
reply views Thread by GrandpaB | last post: by
2 posts views Thread by Dale Reed | last post: by
2 posts views Thread by Scirious | last post: by
3 posts views Thread by ZikO | last post: by
4 posts views Thread by Jeff | last post: by
reply views Thread by helraizer1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.