Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.28
|
Leadtools Namespace > RasterImageAnimator Class : Append Method |
public void Append( RasterImage image )
'Declaration
Public Sub Append( _ ByVal image As RasterImage _ )
'Usage
Dim instance As RasterImageAnimator Dim image As RasterImage instance.Append(image)
public void Append( RasterImage image )
function Leadtools.RasterImageAnimator.Append( image )
public: void Append( RasterImage^ image )
If you pass null (Nothing in VisualBasic) in the animatedImage parameter for the RasterImageAnimator constructor, you can use the Append method to add frames to the multi-frame image during the animation. This is useful if you want to play an animated file as it is being loaded using the LoadImage event. If you need to reference the multi-frame image after the animation, you can call the Destroy method before you dispose this RasterImageAnimator object.
After you call Destroy, this RasterImageAnimator object is invalid and you should only call the Dispose method afterwards.
The ValidateLines method lets you validate the lines that the animation playback engine will render to the target image
This example plays an animated GIF file as it loads the file
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.Drawing Private _animator As RasterImageAnimator Private _targetImage As RasterImage Private _graphics As Graphics Private _destRect As LeadRect Private _paintProperties As RasterPaintProperties Sub RasterImageAppendExample(ByVal panel As Panel) ' Initialize the RasterCodecs object Dim codecs As New RasterCodecs() ' An animated GIF file Dim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "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, Nothing) ' Setup our class members used in the event handler _graphics = panel.CreateGraphics() _destRect = LeadRect.FromLTRB(panel.ClientRectangle.Left, panel.ClientRectangle.Top, panel.ClientRectangle.Right, panel.ClientRectangle.Bottom) _paintProperties = RasterPaintProperties.Default _paintProperties.PaintEngine = RasterPaintEngine.GdiPlus ' Hook to the LoadImage event and load the file 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() 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 LeadRect Select Case (state) Case RasterImageAnimatorState.WaitInput _animator.CancelWait() Case RasterImageAnimatorState.PostClear, _ RasterImageAnimatorState.PostRender updateRect = _animator.GetUpdateRectangle(True) RasterImagePainter.Paint(_targetImage, _graphics, LeadRect.Empty, updateRect, _destRect, LeadRect.Empty, _paintProperties) End Select Exit Do Loop End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.Drawing; RasterImageAnimator _animator; RasterImage _targetImage; Graphics _graphics; LeadRect _destRect; RasterPaintProperties _paintProperties; public void RasterImageAppendExample(Panel panel) { // Initialize the RasterCodecs object RasterCodecs codecs = new RasterCodecs(); // An animated GIF file string fileName = Path.Combine(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 = LeadRect.FromLTRB(panel.ClientRectangle.Left, panel.ClientRectangle.Top, panel.ClientRectangle.Right, panel.ClientRectangle.Bottom); _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(); } 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(); LeadRect updateRect; switch(state) { case RasterImageAnimatorState.WaitInput: _animator.CancelWait(); break; case RasterImageAnimatorState.PostClear: case RasterImageAnimatorState.PostRender: updateRect = _animator.GetUpdateRectangle(true); RasterImagePainter.Paint(_targetImage, _graphics, LeadRect.Empty, updateRect, _destRect, LeadRect.Empty, _paintProperties); break; } break; } }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; RasterImageAnimator _animator; RasterImage _targetImage; LeadRect _destRect; public async Task RasterImageAppendExample() { // Initialize the RasterCodecs object RasterCodecs codecs = new RasterCodecs(); // An animated GIF file string srcFileName = @"Assets\Eye.gif"; // load the first frame, so we have the palette and a target image for playback StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage _targetImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); // Create the animator _animator = new RasterImageAnimator(_targetImage, null); // Setup our class members used in the event handler _destRect = LeadRectHelper.FromLTRB(0, 0, 400, 400); // Hook to the LoadImage event and load the file codecs.LoadImage += new EventHandler<CodecsLoadImageEventArgs>(codecs_LoadImage); loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); codecs.LoadImage -= new EventHandler<CodecsLoadImageEventArgs>(codecs_LoadImage); _animator.Dispose(); _animator = null; _targetImage.Dispose(); codecs.Dispose(); } 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(); LeadRect updateRect; switch (state) { case RasterImageAnimatorState.WaitInput: _animator.CancelWait(); break; case RasterImageAnimatorState.PostClear: case RasterImageAnimatorState.PostRender: updateRect = _animator.GetUpdateRectangle(true); // Render the image here, for example, set the frame to a viewer control // rasterImageViewer.Image = _targetImage; break; } break; } }