当前位置:酷酷问答>百科知识>vb.net制作gif图片源码

vb.net制作gif图片源码

2024-12-08 07:47:37 编辑:zane 浏览量:584

vb.net制作gif图片源码

的有关信息介绍如下:

vb.net制作gif图片源码

vb.net

建立窗体

分别为三个按钮添加代码

'生成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

'分解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

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

版权声明:文章由 酷酷问答 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.kukuwd.com/article/157209.html
热门文章