HighTechTalks DotNet Forums  

GIF not animating after resize

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss GIF not animating after resize in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Fong Lun
 
Posts: n/a

Default GIF not animating after resize - 03-27-2007 , 07:07 PM






I have a GIF which its dimensions is 200x300 pixels and it is animating fine.
But after i resize it to smaller dimensions (133x200 pixels), it doesn't
animate anymore.

Why is it not animating ?

Thanks.

Reply With Quote
  #2  
Old   
Fong Lun
 
Posts: n/a

Default RE: GIF not animating after resize - 03-27-2007 , 08:10 PM








"Fong Lun" wrote:

Quote:
I have a GIF which its dimensions is 200x300 pixels and it is animating fine.
But after i resize it to smaller dimensions (133x200 pixels), it doesn't
animate anymore.

Why is it not animating ?

Thanks.
I am doing this in ASP.NET to display any images (including png, jpg,
gif...) in a <img> tag in a web page. I have put a size limit to the
container to display the image (gif for this example). This is how i decide
whether to resize the gif in my code.

1. The gif is in a table in SQL Server 2005 with image data type.
2. I retrieve the gif from the table using SELECT statement.
3. Below is my codes

Dim b() As Byte = data(0) 'data(0) is the image which is retrieved from a
SELECT statement
Dim img As New Bitmap(New MemoryStream(b))
Dim imgformat As System.Drawing.Imaging.ImageFormat =
System.Drawing.Imaging.ImageFormat.Gif

'the original gif dimensions is 200x300pixels
Dim h As Integer = img.Height
Dim w As Integer = img.Width

If h > 200 or w > 200 Then
If h > w Then
w = (200 / h) * w
h = 200
Else
h = (200 / w) * h
w = 200
End If
End If

Dim bmp As New Bitmap(w, h)
Dim gph As Graphics = Graphics.FromImage(bmp)
gph.InterpolationMode = Drawing2D.InterpolationMode.High
gph.DrawImage(img, 0, 0, w, h)

Dim ms As New MemoryStream
Dim picdata() As Byte

bmp.Save(ms, imgformat)
picdata = ms.GetBuffer

gph.Dispose()
bmp.Dispose()

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "image/gif"
Response.BinaryWrite(picdata)



Reply With Quote
  #3  
Old   
Andrew Kirillov
 
Posts: n/a

Default Re: GIF not animating after resize - 03-28-2007 , 05:50 AM



Hello,

When you load animated GIF as a Bitmap in .NET, it loads only first
frame of the animation. So after processing and saving it you will get
regular one-frame GIF. More of it, you create new bitmap using
Graphics and drawing to it of one frame only.

Take a look at the next article. Hope it will help.
http://www.codeproject.com/dotnet/NGif.asp

Sincerely,
Andrew
------
AForge.NET - open source framework for AI and CV
http://code.google.com/p/aforge/


On Mar 28, 3:10 am, Fong Lun <Fong... (AT) discussions (DOT) microsoft.com>
wrote:
Quote:
"Fong Lun" wrote:
I have a GIF which its dimensions is 200x300 pixels and it is animating fine.
But after i resize it to smaller dimensions (133x200 pixels), it doesn't
animate anymore.

Why is it not animating ?

Thanks.

I am doing this in ASP.NET to display any images (including png, jpg,
gif...) in a <img> tag in a web page. I have put a size limit to the
container to display the image (gif for this example). This is how i decide
whether to resize the gif in my code.

1. The gif is in a table in SQL Server 2005 with image data type.
2. I retrieve the gif from the table using SELECT statement.
3. Below is my codes

Dim b() As Byte = data(0) 'data(0) is the image which is retrieved from a
SELECT statement
Dim img As New Bitmap(New MemoryStream(b))
Dim imgformat As System.Drawing.Imaging.ImageFormat =
System.Drawing.Imaging.ImageFormat.Gif

'the original gif dimensions is 200x300pixels
Dim h As Integer = img.Height
Dim w As Integer = img.Width

If h > 200 or w > 200 Then
If h > w Then
w = (200 / h) * w
h = 200
Else
h = (200 / w) * h
w = 200
End If
End If

Dim bmp As New Bitmap(w, h)
Dim gph As Graphics = Graphics.FromImage(bmp)
gph.InterpolationMode = Drawing2D.InterpolationMode.High
gph.DrawImage(img, 0, 0, w, h)

Dim ms As New MemoryStream
Dim picdata() As Byte

bmp.Save(ms, imgformat)
picdata = ms.GetBuffer

gph.Dispose()
bmp.Dispose()

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "image/gif"
Response.BinaryWrite(picdata)



Reply With Quote
  #4  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: GIF not animating after resize - 03-28-2007 , 10:12 AM



The gdiplus .gif Encoder does not support .gif frames.

The .gif Encoder/Decoder in the new Microsoft "Windows Imaging Component" is
capable of reading, writing .gif frames.

It is supported on Windows XP SP2 and Windows Server 2003.

"Fong Lun" <FongLun (AT) discussions (DOT) microsoft.com> wrote

Quote:

"Fong Lun" wrote:

I have a GIF which its dimensions is 200x300 pixels and it is animating
fine.
But after i resize it to smaller dimensions (133x200 pixels), it doesn't
animate anymore.

Why is it not animating ?

Thanks.

I am doing this in ASP.NET to display any images (including png, jpg,
gif...) in a <img> tag in a web page. I have put a size limit to the
container to display the image (gif for this example). This is how i
decide
whether to resize the gif in my code.

1. The gif is in a table in SQL Server 2005 with image data type.
2. I retrieve the gif from the table using SELECT statement.
3. Below is my codes

Dim b() As Byte = data(0) 'data(0) is the image which is retrieved from
a
SELECT statement
Dim img As New Bitmap(New MemoryStream(b))
Dim imgformat As System.Drawing.Imaging.ImageFormat =
System.Drawing.Imaging.ImageFormat.Gif

'the original gif dimensions is 200x300pixels
Dim h As Integer = img.Height
Dim w As Integer = img.Width

If h > 200 or w > 200 Then
If h > w Then
w = (200 / h) * w
h = 200
Else
h = (200 / w) * h
w = 200
End If
End If

Dim bmp As New Bitmap(w, h)
Dim gph As Graphics = Graphics.FromImage(bmp)
gph.InterpolationMode = Drawing2D.InterpolationMode.High
gph.DrawImage(img, 0, 0, w, h)

Dim ms As New MemoryStream
Dim picdata() As Byte

bmp.Save(ms, imgformat)
picdata = ms.GetBuffer

gph.Dispose()
bmp.Dispose()

Response.Clear()
Response.ClearHeaders()
Response.ContentType = "image/gif"
Response.BinaryWrite(picdata)




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.