Problem with Animated GIFs

  • Thread starter Thread starter Phil
  • Start date Start date
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.
 
Hi Phil,

Thank you for your prompt response.

I have downloaded the two GIFs you provide and test them in my application.
These two GIFs don't seem to have any difference from the GIF I previously
used in my test application. The only difference when the GIFs are
displayed in a WinForm and in IE is that the animation is a little slower
in the former case than in the latter case.
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.

When the test1.gif is display in a PictureBox or drawn on a WinForm using
ImageAnimator, I see the following numbers appearing in sequence and loop:
1, 2, 3 ,4, 5

Since I couldn't reproduce the above problem on my side, could you please
send me a simple sample project that could just reproduce this problem? To
get my actual email address, remove 'online' from my displayed email
address.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hello Linda,

Thanks for the response. I don't think sending you any sample code will make
any difference. I get the problem simply by creating a new project, adding a
picturebox to the form, and loading in my GIF file.
My code using the ImageAnimator is pretty much identical to the example in
the help for the Animate method.
I suspect the problem is to do with timing, perhaps my pc is slower (or
faster) than
yours, or has some background tasks running which is slowing it down.

Did you see this message:
in which I proposed a theory as to what might be causing the problem?

Cheers,
Phil.
 
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
 
Armin Zingler said:
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 Panel> Display> Settings> Advanced> Troubleshooting
Does it make a difference?

No. I set the acceleration to None, but it makes no difference.
 
Phil said:
Control Panel> Display> Settings> Advanced> Troubleshooting

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
 
I have AXBrowse.AXBrowser but not AXAnimation.
Presumably this is something that is part of some other application and
needs to be installed separately.


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
 
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
 
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
 
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.
 
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
 
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.
 
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
 
Back
Top