vb.net制作gif图片源码

 时间:2026-02-14 14:17:45

1、建立窗体

vb.net制作gif图片源码

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


  • 批处理文件12--写入法定义一个变量
  • VBS 怎样自动登录网页
  • 易语言教程 日期框组件的使用
  • linux如何查找特定程序
  • 表格制作软件FineReport教程:[22]插入删除行
  • 热门搜索
    套内面积怎么算 创业板股票怎么买 电脑怎么连接蓝牙 落枕了怎么快速好起来 怎么画漫画 怎么文爱 颦怎么读 六边形怎么画 下水道堵了怎么办 手抓饼怎么做