1、建立窗体

2、分别为三个按钮添加代码 '生成gif Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim imageFilePaths As [String]() = New [String]() {"d:\1.jpg", "d:\2.jpg", "d:\3.jpg"} Dim outputFilePath As [String] = "d:\test.gif" Dim AGE As New Gif.Components.AnimatedGifEncoder() AGE.Start(outputFilePath) AGE.SetDelay(500) AGE.SetRepeat(0) Dim i As Integer = 0, count As Integer = imageFilePaths.Length While i < count AGE.AddFrame(Image.FromFile(imageFilePaths(i))) System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While AGE.Finish() End Sub
3、 '分解gif Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim outputPath As String = "d:\a\" Dim gifDecoder As New Gif.Components.GifDecoder() gifDecoder.Read("d:\test.gif") Dim i As Integer = 0, count As Integer = gifDecoder.GetFrameCount() While i < count Dim frame As Image = gifDecoder.GetFrame(i) frame.Save(outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png) System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While End Sub
4、 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'GDI显示动态GIF Dim animatedGif As New Bitmap("d:\test.gif") Dim PropertyTagFrameDelay As Integer = &H5100 Dim propItem As Imaging.PropertyItem = animatedGif.GetPropertyItem(PropertyTagFrameDelay) Dim bytes() As Byte = propItem.Value Dim frameDimension As New Imaging.FrameDimension(animatedGif.FrameDimensionsList(0)) Dim frameCount As Integer = animatedGif.GetFrameCount(Imaging.FrameDimension.Time) Dim delays(frameCount) As Integer Dim i As Integer For i = 0 To frameCount - 1 delays(i) = BitConverter.ToInt32(bytes, i * 4) Next For i = 0 To animatedGif.GetFrameCount(frameDimension) - 1 animatedGif.SelectActiveFrame(frameDimension, i) Dim memoryStream As New System.IO.MemoryStream animatedGif.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp) PictureBox1.Image = System.Drawing.Image.FromStream(memoryStream) Application.DoEvents() Threading.Thread.Sleep(delays(i) * 10) Next End Sub