|
|
|
Click here to copy the following block |
Class Animation Implements IDisposable
Dim m_Img As System.Drawing.Image Dim m_Frames As New System.Collections.ArrayList Dim m_FrameCount As Integer
Sub New(ByVal imgPath As String) m_Img = System.Drawing.Image.FromFile(imgPath)
If System.Drawing.ImageAnimator.CanAnimate(m_Img) = False Then m_Img.Dispose() Throw New ArgumentException("This is not an animated image") End If
Dim fdl As New Drawing.Imaging.FrameDimension(m_Img.FrameDimensionsList _ (0)) m_FrameCount = m_Img.GetFrameCount(fdl)
AddCurrentFrame() System.Drawing.ImageAnimator.Animate(m_Img, New EventHandler(AddressOf _ OnFrameChanged))
Do Loop Until Done End Sub
Public ReadOnly Property FrameCount() As Integer Get Return m_FrameCount End Get End Property
Public ReadOnly Property Frame(ByVal index As Integer) As _ System.Drawing.Bitmap Get Return DirectCast(m_Frames(index), System.Drawing.Bitmap) End Get End Property
Public Sub Dispose() Implements System.IDisposable.Dispose StopAnimate() End Sub
Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As EventArgs) If Done Then StopAnimate() Exit Sub End If
System.Drawing.ImageAnimator.UpdateFrames(m_Img) AddCurrentFrame() End Sub
Private Sub AddCurrentFrame() Dim bmp As New System.Drawing.Bitmap(m_Img.Width, m_Img.Height) Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage _ (DirectCast(bmp, System.Drawing.Image)) g.DrawImage(m_Img, 0, 0) m_Frames.Add(bmp) End Sub
Private ReadOnly Property Done() As Boolean Get Return m_Frames.Count = FrameCount End Get End Property
Private Sub StopAnimate() System.Drawing.ImageAnimator.StopAnimate(m_Img, _ New EventHandler(AddressOf OnFrameChanged)) m_Img.Dispose() End Sub End Class |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|