←Select platform

RasterImageAnimator Constructor

Summary
Constructs a new RasterImageAnimator object using the specified parameters.
Syntax
C#
Objective-C
C++/CLI
Python
- (nullable instancetype)initWithTargetImage:(LTRasterImage *)targetImage animatedImage:(LTRasterImage *)animatedImage error:(NSError **)error; 
public: 
RasterImageAnimator(  
   RasterImage^ targetImage, 
   RasterImage^ animatedImage 
) 
__init__(self,targetImage,animatedImage) # Overloaded constructor 

Parameters

targetImage
A RasterImage object referencing the target image.

animatedImage
A RasterImage object containing the frames to be played. This object must be a multi-frame image (The value of RasterImage.AnimationGlobalLoop must be something other than -1. You can also pass a null reference (Nothing in VisualBasic) to let the method create an empty multi-frame image.

Remarks targetImage must be allocated before calling this method

If you pass null (Nothing in VisualBasic) in the  animatedImage parameter, 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. If you need to reference the multi-frame image after the animation, you can call the Destroy method before you dispose this RasterImageAnimator object.

The RasterImageAnimator class also implements the IDisposable interface, it is recommended that you follow the standard .NET dispose pattern when using the RasterImageAnimator class. For more information, refer to IDisposable.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Drawing; 
 
 
public void RasterImageAnimatorExample(Panel panel) 
{ 
	// Initialize the RasterCodecs object 
	RasterCodecs codecs = new RasterCodecs(); 
 
	// When loading the animated GIF file, we have two means to load all pages into memory 
	// Option 1: Set the Load All Pages to true, then specify just the filename 
	string fileName = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif"); 
	codecs.Options.Load.AllPages = true; 
	RasterImage animatedImage = codecs.Load(fileName); 
 
	// Option 2: Specify which pages to load, -1 means all pages 
	// Load the animated GIF file  
	//RasterImage animatedImage = codecs.Load(filename, 0, CodecsLoadByteOrder.Bgr, 1, -1) 
 
	// Create the target image, we want it to be in the animated image size 
	RasterImage targetImage = new RasterImage( 
	   RasterMemoryFlags.Conventional, 
	   animatedImage.AnimationGlobalSize.Width, 
	   animatedImage.AnimationGlobalSize.Height, 
	   animatedImage.BitsPerPixel, 
	   animatedImage.Order, 
	   animatedImage.ViewPerspective, 
	   null, 
	   IntPtr.Zero, 
	   0); 
 
	// Copy the palette from the animated image to this newly created image 
	animatedImage.CopyPaletteTo(targetImage); 
 
	// Create the RasterImageAnimator object 
	RasterImageAnimator animator = new RasterImageAnimator(targetImage, animatedImage); 
 
	// Animate it 
 
	// Use GDI+ paint engine to support transparent colors 
	RasterPaintProperties props = RasterPaintProperties.Default; 
	props.PaintEngine = RasterPaintEngine.GdiPlus; 
 
	Graphics g = panel.CreateGraphics(); 
 
	RasterImageAnimatorState state; 
	do 
	{ 
		LeadRect srcRect = new LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight); 
		LeadRect updateRect; 
		LeadRect destRect; 
 
		state = animator.Process(); 
 
		switch (state) 
		{ 
			case RasterImageAnimatorState.WaitDelay: 
			case RasterImageAnimatorState.WaitInputDelay: 
			case RasterImageAnimatorState.Render: 
				// Continue processing 
				break; 
 
			case RasterImageAnimatorState.WaitInput: 
				// In case the animated image has the "wait for user input" flags, 
				// cancel the waiting 
				animator.CancelWait(); 
				break; 
 
			case RasterImageAnimatorState.PostClear: 
			case RasterImageAnimatorState.PostRender: 
				// Get the area in the target image that has changed 
				updateRect = animator.GetUpdateRectangle(true); 
 
				// Paint it 
				destRect = new LeadRect(0, 0, targetImage.ImageWidth, targetImage.ImageHeight); 
 
				RasterImagePainter.Paint(targetImage, g, srcRect, updateRect, destRect, destRect, props); 
				break; 
 
			default: 
				break; 
		} 
	} 
	while (state != RasterImageAnimatorState.End); 
 
	g.Dispose(); 
 
	animator.Dispose(); 
 
	targetImage.Dispose(); 
	animatedImage.Dispose(); 
 
	codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.16
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.