locked
Preserve GIF animation on resize & save RRS feed

  • Question

  • User-217808514 posted

    Hi,

    I can't quite believe that this hasn't been encountered and handled hundreds of times before, but it seems not. There we go. The problem is very simple. If you do this:

            Dim resizedImage As System.Drawing.Bitmap

            Dim Width, Height As Integer

            resizedImage = New System.Drawing.Bitmap(Width,Height)
            canvas = System.Drawing.Graphics.FromImage(resizedImage)
            canvas.DrawImage(imgToResize, 0, 0, calculatedSize.Width, calculatedSize.Height)

    And "imgToResize" is an animated GIF, you loose the animation. I've tried a variety of methods to try and resize the image including using Image.GetThumbnailImage and some of the classes in System.Graphics but the result is always the same: the image saves but it looses it's animation.

    Doing some research on the internet I discovered that you can set a System.Drawing.Imaging.EncoderValue.MultiFrame Encoding Parameter - but it only seems to work for animated TIFF files. So that's not a lot of help.

    I also discovered the System.Drawing.ImageAnimator class which was new to me, but again this seems to be made to render animated images rather than to help resize them, so I can't see how it's helpful.

    Can anyone tell me how I can resize an animated GIF and retain it's animation?

    Cheers,

    Matt

    Wednesday, November 3, 2010 8:30 AM

Answers

  • User1051163829 posted

     Hi,

    I get the general feeling that isn't easy (just had a quick snoot around). Obviously you could do this in Photoshop/other image manipulating software so i'm wandering if it's possible to tap into these by using a helper method? It could be a new route to research as I'm not really sure keeping the animation is possible by using the standard .NET Classes.

    HTH's

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 4, 2010 6:56 PM

All replies

  • User1051163829 posted

     Hi,

    I get the general feeling that isn't easy (just had a quick snoot around). Obviously you could do this in Photoshop/other image manipulating software so i'm wandering if it's possible to tap into these by using a helper method? It could be a new route to research as I'm not really sure keeping the animation is possible by using the standard .NET Classes.

    HTH's

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 4, 2010 6:56 PM
  • User-217808514 posted

    Interesting idea on using an API call to do the job. I have no idea if photoshop or anything else offers something that will interface with .net (we use GIMP here) but I'll look into it.


    Friday, November 5, 2010 5:21 AM