Problem with Animated GIFs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil

    #1

    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.


  • Cor Ligthert[MVP]

    #2
    Re: Problem with Animated GIFs

    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:13c0rc08fd dcp56@corp.supe rnews.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.
    >

    Comment

    • Linda Liu [MSFT]

      #3
      RE: Problem with Animated GIFs

      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.

      Comment

      • Phil

        #4
        Re: Problem with Animated GIFs


        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.


        Comment

        • Phil

          #5
          Re: Problem with Animated GIFs

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


          Comment

          • Phil

            #6
            Re: Problem with Animated GIFs

            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.




            Comment

            • Armin Zingler

              #7
              Re: Problem with Animated GIFs

              "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

              Comment

              • Phil

                #8
                Re: Problem with Animated GIFs

                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.



                Comment

                • Phil

                  #9
                  Re: Problem with Animated GIFs

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


                  Comment

                  • Phil

                    #10
                    Re: Problem with Animated GIFs


                    "Phil" <N/Awrote in message news:13c3a55hsd t1450@corp.supe rnews.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.Threa d.Sleep(10)

                    before calling UpdateFrames.


                    Comment

                    • Phil

                      #11
                      Re: Problem with Animated GIFs


                      "Phil" <N/Awrote in message news:13c0rc08fd dcp56@corp.supe rnews.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

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


                      Comment

                      • Hoop

                        #12
                        Re: Problem with Animated GIFs

                        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

                        Comment

                        • Phil

                          #13
                          Re: Problem with Animated GIFs

                          Hi,
                          Can you use AxAnimation in Express? It would be in the Tools/Choose
                          ToolBox items, and select the Com tab.
                          I have AXBrowse.AXBrow ser 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.


                          Comment

                          • Phil

                            #14
                            Re: Problem with Animated GIFs

                            What does seem to fix it though is calling
                            Threading.Threa d.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.


                            Comment

                            • Phil

                              #15
                              Displaying AVIs (was RE: Problem with Animated GIFs)

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


                              Comment

                              Working...