Appends an image to the animated multi-frame image during an animation playback.
Syntax
Parameters
- image
- A RasterImage that contains 1 or more frames to be added to the animation.
Example
This example plays an animated GIF file as it loads the file
Visual Basic | Copy Code |
---|
Private _animator As RasterImageAnimator
Private _targetImage As RasterImage
Private _graphics As Graphics
Private _destRect As Rectangle
Private _paintProperties As RasterPaintProperties
Sub RasterImageAppendExample(ByVal panel As Panel)
RasterCodecs.Startup()
Dim codecs As New RasterCodecs()
Dim fileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Eye.gif"
_targetImage = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
_animator = New RasterImageAnimator(_targetImage, Nothing)
_graphics = panel.CreateGraphics()
_destRect = panel.ClientRectangle
_paintProperties = RasterPaintProperties.Default
_paintProperties.PaintEngine = RasterPaintEngine.GdiPlus
AddHandler codecs.LoadImage, AddressOf codecs_LoadImage
codecs.Load(fileName)
RemoveHandler codecs.LoadImage, AddressOf codecs_LoadImage
_graphics.Dispose()
_animator.Dispose()
_animator = Nothing
_targetImage.Dispose()
codecs.Dispose()
RasterCodecs.Shutdown()
End Sub
Sub codecs_LoadImage(ByVal sender As Object, ByVal e As CodecsLoadImageEventArgs)
If ((e.Flags And CodecsLoadImageFlags.FirstRow) = CodecsLoadImageFlags.FirstRow) Then
_animator.Append(e.Image)
End If
_animator.ValidateLines(e.Row, e.Lines)
Dim state As RasterImageAnimatorState = _animator.State
Do While (state <> RasterImageAnimatorState.End)
state = _animator.Process()
Dim updateRect As Rectangle
Select Case (state)
Case RasterImageAnimatorState.WaitInput
_animator.CancelWait()
Case RasterImageAnimatorState.PostClear, _
RasterImageAnimatorState.PostRender
updateRect = _animator.GetUpdateRectangle(True)
_targetImage.Paint(_graphics, Rectangle.Empty, updateRect, _destRect, Rectangle.Empty, _paintProperties)
End Select
Exit Do
Loop
End Sub |
C# | Copy Code |
---|
RasterImageAnimator _animator; RasterImage _targetImage; Graphics _graphics; Rectangle _destRect; RasterPaintProperties _paintProperties; void RasterImageAppendExample(Panel panel) { // Initialize the RasterCodecs object RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // An animated GIF file string fileName = LeadtoolsExamples.Common.ImagesPath.Path + "Eye.gif"; // load the first frame, so we have the palette and a target image for playback _targetImage = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); // Create the animator _animator = new RasterImageAnimator(_targetImage, null); // Setup our class members used in the event handler _graphics = panel.CreateGraphics(); _destRect = panel.ClientRectangle; _paintProperties = RasterPaintProperties.Default; _paintProperties.PaintEngine = RasterPaintEngine.GdiPlus; // Hook to the LoadImage event and load the file codecs.LoadImage += new EventHandler<CodecsLoadImageEventArgs>(codecs_LoadImage); codecs.Load(fileName); codecs.LoadImage -= new EventHandler<CodecsLoadImageEventArgs>(codecs_LoadImage); _graphics.Dispose(); _animator.Dispose(); _animator = null; _targetImage.Dispose(); codecs.Dispose(); RasterCodecs.Shutdown(); } void codecs_LoadImage(object sender, CodecsLoadImageEventArgs e) { if((e.Flags & CodecsLoadImageFlags.FirstRow) == CodecsLoadImageFlags.FirstRow) _animator.Append(e.Image); _animator.ValidateLines(e.Row, e.Lines); RasterImageAnimatorState state = _animator.State; while(state != RasterImageAnimatorState.End) { state = _animator.Process(); Rectangle updateRect; switch(state) { case RasterImageAnimatorState.WaitInput: _animator.CancelWait(); break; case RasterImageAnimatorState.PostClear: case RasterImageAnimatorState.PostRender: updateRect = _animator.GetUpdateRectangle(true); _targetImage.Paint(_graphics, Rectangle.Empty, updateRect, _destRect, Rectangle.Empty, _paintProperties); break; } break; } } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also