How to extract frames from gif

aewarnick

Well-known member
Joined
Jan 29, 2003
Messages
1,031
Bitmap b=new Bitmap((Image)Ims[0]);
IEnumerator E= (b).FrameDimensionsList.GetEnumerator();
E.MoveNext();
b= (Bitmap)E.Current;

Invalid cast exception. I must be doing this wrong. I have look all over the net form information on how to do this but could find nothing.
 
I just opended an animated gif in IrfanView and extracted all the frames.

How do I do that in my program is what I am asking?
 
try this

Code:
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms

Public Module test
	Sub Main()
		Application.Run(New myform)
	End Sub
End Module

Public Class myform
	Inherits System.Windows.Forms.Form
	
        Private components As System.ComponentModel.Container
	Private newimg As Bitmap = New Bitmap("C:\l5r\anielg.gif")
	
	Public Sub New()
	
	
	        MyBase.New()
	        Me.components = New System.ComponentModel.Container()
		ImageAnimator.Animate(newimg, New EventHandler(AddressOf Me.go))
	End Sub
	
	Protected Overrides Sub OnPaint(e As PaintEventArgs)
	    	ImageAnimator.UpdateFrames()
	    	e.Graphics.DrawImage(newimg, 20, 20)
	End Sub
	
	Public Sub go(ByVal sender As Object, ByVal e As EventArgs)
		 Without this line, the form will not keep fireing OnPaint
		Me.Invalidate()
	End Sub
End Class
 
Thank you but I wasnt looking to animate the frames but to extract them from an already existing gif, saving them as individual files.
 
I think you should be able to adapt it to do that.

If you look in the paint sub, it extracts each frame and paints it to the control. I guess all you would need to do is whatever you wanted to do with the image object before.. save it, convert it or whatever..


hope it helps.. I cant explain the code in detail as I found it myself while looking up code for manipulating GIFs.
 
Back
Top