←Select platform

RasterImageAnimationDisposalMethod Enumeration

Summary
Used for the disposal methods used after rendering each frame in an animated image.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public enum RasterImageAnimationDisposalMethod 
typedef NS_ENUM(NSInteger, LTRasterImageAnimationDisposalMethod) { 
 LTRasterImageAnimationDisposalMethodNone = 0,  
 LTRasterImageAnimationDisposalMethodLeave = 1,  
 LTRasterImageAnimationDisposalMethodRestoreBackground = 2,  
 LTRasterImageAnimationDisposalMethodRestorePrevious = 3 
}; 
public final class RasterImageAnimationDisposalMethod 
    extends java.lang.Enum<RasterImageAnimationDisposalMethod> 
public enum class RasterImageAnimationDisposalMethod   
class RasterImageAnimationDisposalMethod(Enum): 
   None = 0 
   Leave = 1 
   RestoreBackground = 2 
   RestorePrevious = 3 
Members
ValueMemberDescription
0NoneDo nothing
1LeaveLeave the target image as is
2RestoreBackgroundRestore the background
3RestorePreviousRestore the previous frame
Remarks

The RasterImageAnimator class will take care of interpreting the value of the disposal method and update the target image accordingly.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Drawing; 
 
 
// WIN32 API 
const int LOGPIXELSY = 90; 
 
[DllImport("gdi32")] 
extern static int GetDeviceCaps(IntPtr hdc, int nIndex); 
 
[DllImport("kernel32")] 
extern static int MulDiv(int nNumber, int nNumerator, int nDenominator); 
 
		public void AnimatedGIFExample() 
{ 
	// The GIF file will contain 4 frames 
	const int frameCount = 4; 
 
	// Each frame is 128 by 128 pixels (the GIF file will have double that size) 
	const int frameWidth = 128; 
	const int frameHeight = 128; 
 
	// Background colors 
	RasterColor[] backColor = 
	{ 
	new RasterColor(0xFF, 0x00, 0x00), 
	new RasterColor(0x00, 0xFF, 0x00), 
	new RasterColor(0x00, 0x00, 0xFF), 
	new RasterColor(0xFF, 0xFF, 0x00) 
 }; 
 
	// Foreground colors 
	RasterColor[] foreColor = 
	{ 
	new RasterColor(0xFF, 0xFF, 0x00), 
	new RasterColor(0xFF, 0x00, 0x00), 
	new RasterColor(0x00, 0xFF, 0x00), 
	new RasterColor(0xFF, 0x00, 0x00) 
 }; 
 
	// Delay in milliseconds 
	int[] delay = 
	{ 
	1000, 
	1000, 
	1000, 
	1000 
 }; 
 
	// Left and top, we want the frames to move to each corner 
	LeadPoint[] offset = 
	{ 
	new LeadPoint(0, 0), 
	new LeadPoint(frameWidth, 0), 
	new LeadPoint(frameWidth, frameHeight), 
	new LeadPoint(0, frameHeight), 
 }; 
 
	RasterImageAnimationDisposalMethod[] disposalMethod = 
	{ 
	RasterImageAnimationDisposalMethod.RestoreBackground, 
	RasterImageAnimationDisposalMethod.RestoreBackground, 
	RasterImageAnimationDisposalMethod.RestoreBackground, 
	RasterImageAnimationDisposalMethod.RestoreBackground 
 }; 
 
	RasterColor backgroundColor = RasterColor.FromKnownColor(RasterKnownColor.Yellow); 
 
	RasterImage image = null; 
	Font font = null; 
	StringFormat stringFormat = null; 
 
	// Create the frames 
	for (int frame = 0; frame < frameCount; frame++) 
	{ 
            RasterImage frameImage = new RasterImage( 
               RasterMemoryFlags.Conventional, 
               frameWidth, 
               frameHeight, 
               24, 
               RasterByteOrder.Bgr, 
               RasterViewPerspective.BottomLeft, 
               null, 
               IntPtr.Zero, 
               0) 
            { 
 
               // Set the frame properties 
               AnimationDelay = delay[frame], 
               AnimationOffset = offset[frame], 
               AnimationDisposalMethod = disposalMethod[frame], 
 
               // Background is white 
               AnimationBackground = backgroundColor 
            }; 
 
            // Draw the number of the frame on its surface 
            IntPtr hdc = RasterImagePainter.CreateLeadDC(frameImage); 
		Graphics g = Graphics.FromHdc(hdc); 
		Rectangle rc = new Rectangle(0, 0, frameWidth, frameHeight); 
 
		Brush brush = new SolidBrush(RasterColorConverter.ToColor(backColor[frame])); 
		g.FillRectangle(brush, rc); 
		brush.Dispose(); 
 
		if (font == null) 
		{ 
			int fontHeight = MulDiv(72, GetDeviceCaps(hdc, LOGPIXELSY), 72); 
			font = new Font("Consolas", fontHeight); 
 
               stringFormat = new StringFormat 
               { 
                  Alignment = StringAlignment.Center, 
                  LineAlignment = StringAlignment.Center 
               }; 
            } 
 
		string str = string.Format("{0}", frame + 1); 
 
		brush = new SolidBrush(RasterColorConverter.ToColor(foreColor[frame])); 
		g.DrawString(str, font, brush, rc, stringFormat); 
		brush.Dispose(); 
 
		g.Dispose(); 
		RasterImagePainter.DeleteLeadDC(hdc); 
 
		if (image == null) 
			image = frameImage; 
		else 
			image.AddPage(frameImage); 
	} 
 
	font.Dispose(); 
	stringFormat.Dispose(); 
 
	// Setup the global image properties 
	image.AnimationGlobalSize = new LeadSize(frameWidth * 2, frameHeight * 2); 
	image.AnimationGlobalLoop = 0; 
	image.AnimationGlobalBackground = backgroundColor; 
 
	// Convert this image to 8 bits/pixel 
	ColorResolutionCommand cmd = new ColorResolutionCommand( 
	   ColorResolutionCommandMode.AllPages, 
	   8, 
	   RasterByteOrder.Rgb, 
	   RasterDitheringMethod.None, 
	   ColorResolutionCommandPaletteFlags.Optimized, 
	   null); 
	cmd.Run(image); 
 
	RasterCodecs codecs = new RasterCodecs(); 
 
	// Setup the GIF save options 
	RasterColor[] animationPalette = image.GetPalette(); 
	codecs.Options.Gif.Save.SetAnimationPalette(animationPalette); 
	codecs.Options.Gif.Save.UseAnimationPalette = true; 
 
	// The GIF Animation width & height, loop and background are 
	// pulled automatically from the image 
 
	// Save the file 
	string fileName = Path.Combine(LEAD_VARS.ImagesDir, "AnimatedGifFile.gif"); 
	codecs.Save(image, fileName, RasterImageFormat.Gif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite); 
 
	image.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.