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:
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
-- Please mark answers as answers! --
-- "SQL has driven more programmers mad than any other language" --
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
Regards,
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
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.
-- Please mark answers as answers! --
-- "SQL has driven more programmers mad than any other language" --
Member
285 Points
226 Posts
Preserve GIF animation on resize & save
Nov 03, 2010 08:30 AM|mattt|LINK
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
-- "SQL has driven more programmers mad than any other language" --
Participant
1406 Points
465 Posts
Re: Preserve GIF animation on resize & save
Nov 04, 2010 06:56 PM|BoogleC|LINK
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
BoogleC
Please mark the right solution as the answer. This helps others find what they're looking for.
Member
285 Points
226 Posts
Re: Preserve GIF animation on resize & save
Nov 05, 2010 05:21 AM|mattt|LINK
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.
-- "SQL has driven more programmers mad than any other language" --