Problem with Animated GIFs

P

Phil

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.
 
L

Linda Liu [MSFT]

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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

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

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.

It may be slower, I'm not sure, but it seems like it may be missing some
frames, and staying on other frames longer. I'll perhaps try a slower
animation to see if I can be a little more specific. e.g. I wonder if it is
perhaps only showing every other frame, or something like that.
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.

Yes, I suspect it is something like that. I wonder if altering the timing
within the GIF will have any effect on this?
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.

Thanks, that would be really useful.
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.

Here is the GIF I've been using (please forgive the dodgy graphics, I'm not
an artist).

http://www.triton-technology.co.uk/Phil/Moulding Machine Product.gif
Thank you for your cooperation and patience!

I did find a way around the problem, which is to add a Web Browser control
on the form, and set:

DocumentText = "<IMG src='" & ImageFileName & " '>"

My GIF has a transparent background though, so I need a way to set the
background colour in the WebBrowser control.
Also this method loads the image from a disk file, it would be useful if I
could store the image in the application resources.

Cheers,
Phil.
 
P

Phil

Phil said:
It may be slower, I'm not sure, but it seems like it may be missing some
frames, and staying on other frames longer. I'll perhaps try a slower
animation to see if I can be a little more specific. e.g. I wonder if it
is
perhaps only showing every other frame, or something like that.
I tried another gif file, and this seems to be exactly the problem.
With the following GIF you can clearly see it shows the frames in this
order: 1,3,5,2,4.
http://www.triton-technology.co.uk/Phil/test1.gif
I notice there is a property on the Form called DoubleBuffering, and I
wonder if this has something to do with it? I tried setting this to True and
False, but it doesn't seem to make any difference. I can't see a similar
property on the PictureBox control.
 
A

Armin Zingler

Phil said:
I tried another gif file, and this seems to be exactly the problem.
With the following GIF you can clearly see it shows the frames in
this order: 1,3,5,2,4.
http://www.triton-technology.co.uk/Phil/test1.gif
I notice there is a property on the Form called DoubleBuffering, and
I wonder if this has something to do with it? I tried setting this
to True and False, but it doesn't seem to make any difference. I
can't see a similar property on the PictureBox control.

Within the IDE or when running the program? In the IDE, I don't see any
animation at all. When running the program, it is displayed correctly. (VB
2005 Express)

In VS 2003: It is displayed correctly animated within the IDE and when
running the program.


Armin
 
P

Phil

You are sure that you set the properties of the picturebox right
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.
 
P

Phil

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.
 
R

rowe_newsgroups

When running the program, it is displayed correctly.
Not for me :(

If you create a new form, with just a picturebox containing the image
does it work? It runs slightly laggy for me but both examples go
through the frames in the correct order.

(Using VS2005 Pro)

Thanks,

Seth Rowe
 
A

Armin Zingler

Phil said:
It makes no difference whether I run the program from within the IDE
or compile it, and run the exe.


I don't see any animation when using the form designer. That is not
a problem. I am only concerned with the runtime behaviour.


Not for me :(


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
 
P

Phil

If you create a new form, with just a picturebox containing the image
does it work?
That's exactly what I am doing.
I created a brand new project, added a picture box to the form and loaded in
the image.
It runs slightly laggy for me but both examples go
through the frames in the correct order.

It is definitely only showing every second frame on my system.

I have also tried using the ImageAnimator instead of a picture box, and this
shows exactly the same behaviour. I seem to be getting the FrameChanged and
Paint Events raised, but DrawImage just seems to redraw the same frame
again, even though UpdateFrames has been called.

I tried calling UpdateFrames twice in my Paint event handler, and now it is
displaying the new frame correctly.
 
P

Phil

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. :-(
 
R

rowe_newsgroups

That's exactly what I am doing.
I created a brand new project, added a picture box to the form and loaded in
the image.


It is definitely only showing every second frame on my system.

I have also tried using the ImageAnimator instead of a picture box, and this
shows exactly the same behaviour. I seem to be getting the FrameChanged and
Paint Events raised, but DrawImage just seems to redraw the same frame
again, even though UpdateFrames has been called.

I tried calling UpdateFrames twice in my Paint event handler, and now it is
displaying the new frame correctly.

I did read an interesting object on painting an animated GIF with GDI+
will searching for anything of use on codeproject.com. The author
wrote a method that splits an animated GIF into it's seperate frames
and then displays them in order in a paint event. Unfortunately, the
article is in C++ so it might be a chore to convert (Unless David
Anton wants to demonstrate his C++ to VB converter....) - but's its a
start.

http://www.codeproject.com/vcpp/gdiplus/imageexgdi.asp

Thanks,

Seth Rowe
 
P

Phil

Phil said:
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.
 
P

Phil

Phil said:
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. "
 
H

Hoop

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
 
P

Phil

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.
 
P

Phil

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Animated gif slow in Picturebox 1
ImageList and animated Gifs 2
Animated GIFs in VB.NET 2005 3
Image Animation 1
multiple animated gifs 1
Animgated GIFS 2
STUPID%20FILE%20NAMES 23
insert an animated .gif 1

Top