New product
This product is no longer in stock
Availability date:
gif vb.net
How to handle, create, paint and play animated gif in VB.NET. Get the animation speed of the gif, with a simple class to learn.Recipient :
* Required fields
or Cancel
Public Class ImageGif
Implements IDisposable
Private _Gif As Bitmap
Private _frameD As Imaging.FrameDimension
Private times() As Byte
Private _nFrames As Integer
Private _currentFrame As Integer
Private _fileName As String
Private _runGif As Boolean
Public Event UpdateGif(ByVal bmpGif As Bitmap)
Private WithEvents AutoUpdater As Timer
Public Sub OpenFile(ByVal filename As String, Optional ByVal autoUpdate As Boolean = True)
'Load the bitmap
_Gif = New Bitmap(filename)
_frameD = New Imaging.FrameDimension(_Gif.FrameDimensionsList(0))
_nFrames = _Gif.GetFrameCount(_frameD)
times = _Gif.GetPropertyItem(&H5100).Value
_runGif = autoUpdate
AutoUpdater = New Timer
AutoUpdater.Interval = 33
AutoUpdater.Enabled = True
End Sub
Public ReadOnly Property GifBitmap() As Bitmap
Get
Return _Gif
End Get
End Property
Public ReadOnly Property nFrames() As Integer
Get
Return _nFrames
End Get
End Property
Public Property currentFrame() As Integer
Get
Return _currentFrame
End Get
Set(ByVal value As Integer)
If value >= _nFrames Then value = 0
If value < 0 Then value = 0
_currentFrame = value
'update bitmap gif
_Gif.SelectActiveFrame(_frameD, _currentFrame)
End Set
End Property
Private Sub UpdateFrameGif() Handles AutoUpdater.Tick
Dim timeDelay As Integer
If _runGif Then
_currentFrame += 1
If _currentFrame >= _nFrames Then _currentFrame = 0
_Gif.SelectActiveFrame(_frameD, _currentFrame)
timeDelay = BitConverter.ToInt32(times, 4 * _currentFrame) * 10
RaiseEvent UpdateGif(_Gif)
AutoUpdater.Interval = timeDelay
End If
End Sub
#Region " IDisposable Support "
Private disposedValue As Boolean = False
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
AutoUpdater.Enabled = False
_Gif.Dispose()
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
Private WithEvents Gif As ImageGif
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Gif = New ImageGif
Gif.OpenFile("C:ImagesGif1.gif")
Me.DoubleBuffered = True
End Sub
Private Sub Gif_UpdateGif(ByVal bmpGif As System.Drawing.Bitmap) Handles Gif.UpdateGif
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(Gif.GifBitmap, New Point(0, 0))
End Sub
Written by:
Elimar G.
06/03/2019
Muy bien
Esto no existia en español! genial.
NO registration required!
If the question you have has not yet been answered here, use the form below to ask something about this addon.
If the download link redirects to another product that is not described in the article or is broken, report it using our Reporting Form