public int AnimationGlobalLoop { get; set; } Public Property AnimationGlobalLoop As Integer @property (nonatomic, assign) NSInteger animationGlobalLoop public int getAnimationGlobalLoop()public void setAnimationGlobalLoop(int value)
An integer value that indicates the global loop count for animated images. The following are valid values:
| Value | Meaning |
|---|---|
| -1 | No looping. This is the default value and it means this image is not animated. This is the case with multipage TIF files, for example. |
| 0 | Continuous looping. The animation should repeat itself indefinitely. |
| < 0 | N looping. The animation should repeat itself N times. |
An image is considered to have animation if the value of AnimationGlobalLoop is not -1 and the image has more than one frame (PageCount is greater than 1).
When the value of this property is changed, the Changed event will fire with RasterImageChangedFlags set to RasterImageChangedFlags.AnimationProperties.
For more information, refer to Implementing Animation.
This example will create an animated GIF file that shows the frame number moving into the four corners
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.Drawing;// WIN32 APIconst 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 framesconst 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 colorsRasterColor[] backColor ={new RasterColor(0xFF, 0x00, 0x00),new RasterColor(0x00, 0xFF, 0x00),new RasterColor(0x00, 0x00, 0xFF),new RasterColor(0xFF, 0xFF, 0x00)};// Foreground colorsRasterColor[] foreColor ={new RasterColor(0xFF, 0xFF, 0x00),new RasterColor(0xFF, 0x00, 0x00),new RasterColor(0x00, 0xFF, 0x00),new RasterColor(0xFF, 0x00, 0x00)};// Delay in millisecondsint[] delay ={1000,1000,1000,1000};// Left and top, we want the frames to move to each cornerLeadPoint[] 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 framesfor (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 propertiesframeImage.AnimationDelay = delay[frame];frameImage.AnimationOffset = offset[frame];frameImage.AnimationDisposalMethod = disposalMethod[frame];// Background is whiteframeImage.AnimationBackground = backgroundColor;// Draw the number of the frame on its surfaceIntPtr 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();stringFormat.Alignment = StringAlignment.Center;stringFormat.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;elseimage.AddPage(frameImage);}font.Dispose();stringFormat.Dispose();// Setup the global image propertiesimage.AnimationGlobalSize = new LeadSize(frameWidth * 2, frameHeight * 2);image.AnimationGlobalLoop = 0;image.AnimationGlobalBackground = backgroundColor;// Convert this image to 8 bits/pixelColorResolutionCommand cmd = new ColorResolutionCommand(ColorResolutionCommandMode.AllPages,8,RasterByteOrder.Rgb,RasterDitheringMethod.None,ColorResolutionCommandPaletteFlags.Optimized,null);cmd.Run(image);RasterCodecs codecs = new RasterCodecs();// Setup the GIF save optionsRasterColor[] 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 filestring 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:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.Drawing' WIN32 APIConst LOGPIXELSY As Integer = 90<DllImport("gdi32")>Shared Function GetDeviceCaps(ByVal hdc As IntPtr, ByVal nIndex As Integer) As IntegerEnd Function<DllImport("kernel32")>Shared Function MulDiv(ByVal nNumber As Integer, ByVal nNumerator As Integer, ByVal nDenominator As Integer) As IntegerEnd FunctionSub AnimatedGIFExample()' The GIF file will contain 4 framesConst frameCount As Integer = 4' Each frame is 128 by 128 pixels (the GIF file will have double that size)Const frameWidth As Integer = 128Const frameHeight As Integer = 128' Background colorsDim backColor() As RasterColor ={New RasterColor(&HFF, &H0, &H0),New RasterColor(&H0, &HFF, &H0),New RasterColor(&H0, &H0, &HFF),New RasterColor(&HFF, &HFF, &H0)}' Foreground colorsDim foreColor() As RasterColor ={New RasterColor(&HFF, &HFF, &H0),New RasterColor(&HFF, &H0, &H0),New RasterColor(&H0, &HFF, &H0),New RasterColor(&HFF, &H0, &H0)}' Delay in millisecondsDim delay() As Integer ={1000,1000,1000,1000}' Left and top, we want the frames to move to each cornerDim offset() As LeadPoint ={New LeadPoint(0, 0),New LeadPoint(frameWidth, 0),New LeadPoint(frameWidth, frameHeight),New LeadPoint(0, frameHeight)}Dim disposalMethod() As RasterImageAnimationDisposalMethod ={RasterImageAnimationDisposalMethod.RestoreBackground,RasterImageAnimationDisposalMethod.RestoreBackground,RasterImageAnimationDisposalMethod.RestoreBackground,RasterImageAnimationDisposalMethod.RestoreBackground}Dim backgroundColor As RasterColor = RasterColor.FromKnownColor(RasterKnownColor.Yellow)Dim image As RasterImage = NothingDim myFont As Font = NothingDim myStringFormat As StringFormat = Nothing' Create the framesFor frame As Integer = 0 To frameCount - 1Dim frameImage As New RasterImage(RasterMemoryFlags.Conventional,frameWidth,frameHeight,24,RasterByteOrder.Bgr,RasterViewPerspective.BottomLeft,Nothing,IntPtr.Zero,0)' Set the frame propertiesframeImage.AnimationDelay = delay(frame)frameImage.AnimationOffset = offset(frame)frameImage.AnimationDisposalMethod = disposalMethod(frame)' Background is whiteframeImage.AnimationBackground = backgroundColor' Draw the number of the frame on its surfaceDim hdc As IntPtr = RasterImagePainter.CreateLeadDC(frameImage)Dim g As Graphics = Graphics.FromHdc(hdc)Dim rc As New Rectangle(0, 0, frameWidth, frameHeight)Dim brush As New SolidBrush(RasterColorConverter.ToColor(backColor(frame)))g.FillRectangle(brush, rc)brush.Dispose()If (myFont Is Nothing) ThenDim fontHeight As Integer = MulDiv(72, GetDeviceCaps(hdc, LOGPIXELSY), 72)myFont = New Font("Consolas", fontHeight)myStringFormat = New StringFormat()myStringFormat.Alignment = StringAlignment.CentermyStringFormat.LineAlignment = StringAlignment.CenterEnd IfDim str As String = String.Format("{0}", frame + 1)brush = New SolidBrush(RasterColorConverter.ToColor(foreColor(frame)))g.DrawString(str, myFont, brush, rc, myStringFormat)brush.Dispose()g.Dispose()RasterImagePainter.DeleteLeadDC(hdc)If (image Is Nothing) Thenimage = frameImageElseimage.AddPage(frameImage)End IfNextmyFont.Dispose()myStringFormat.Dispose()' Setup the global image propertiesimage.AnimationGlobalSize = New LeadSize(frameWidth * 2, frameHeight * 2)image.AnimationGlobalLoop = 0image.AnimationGlobalBackground = backgroundColor' Convert this image to 8 bits/pixelDim cmd As New ColorResolutionCommand(ColorResolutionCommandMode.AllPages,8,RasterByteOrder.Rgb,RasterDitheringMethod.None,ColorResolutionCommandPaletteFlags.Optimized,Nothing)cmd.Run(image)Dim codecs As New RasterCodecs()' Setup the GIF save optionsDim animationPalette() As RasterColor = 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 fileDim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "AnimatedGifFile.gif")codecs.Save(image, fileName, RasterImageFormat.Gif, 8, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)image.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"End Class
AnimationWaitUserInput Property
AnimationDisposalMethod Property
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
