Select language
  1. Products
  2. Aspose.Imaging
  3. Animation maker
clearbit icon

Create animation for .NET

Buy for $99
Share
Instagram Logo Dribbble Logo Twitter Logo Youtube Logo

How to make animation Using .NET Library

In order to create animation, we’ll use Aspose.Imaging for .NET API which is a feature-rich, powerful and easy to use image manipulation API for net platform. Open NuGet package manager, search for Aspose.Imaging and install. You may also use the following command from the Package Manager Console.

1
Install-Package Aspose.Imaging

Make animation Image via .NET

You need Aspose.Imaging Animation Maker for .NET metered license to try the code in your environment.

  1. Create animated image with as an instance of specific Image class.
  2. Set the animation optons
  3. Add the frames
  4. Save or export image in the desired animated format, defined by the options

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Core
  • Development environment like Visual Studio Code or Microsoft Visual Studio.
  • Aspose.Imaging for .NET DLL referenced in your project.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
 using Aspose.Imaging;
 using Aspose.Imaging.FileFormats.Gif;
 using Aspose.Imaging.FileFormats.Gif.Blocks;
 using Aspose.Imaging.ImageOptions;
 using Aspose.Imaging.Sources;

namespace CSharpTutorials
{
	class Program
	{
		static void Main(string[] args)
		{
			Metered metered = new Metered();
			metered.SetLicense("***********", // public key
							   "***********"  // private key
							  );

			// This code creates the animation from the image frames
			const int AnimationDuration = 1000;
			const int FrameDuration = 42;

			GifImage gifImage = null;
			try
			{
				foreach (var inputFilePath in Directory.GetFiles(inputFilesPath, fileMask))
				{
					RasterImage sourceImage = (RasterImage)Image.Load(inputFilePath);
					{
						if (gifImage == null)
						{
							GifOptions createOptions = new GifOptions
							{
								Source = new FileCreateSource(outputFilePath, false),
								BackgroundColor = Color.Transparent,
								FullFrame = true,
								LoopsCount = (int)(AnimationDuration / FrameDuration),
								Palette = ColorPaletteHelper.GetCloseImagePalette(sourceImage, 256)
							};

							gifImage = (GifImage)Image.Create(
											 createOptions,
									sourceImage.Width,
									sourceImage.Height);

							gifImage.InsertBlock(0, new GifGraphicsControlBlock());
							gifImage.SetFrameTime((ushort)FrameDuration);
							if (gifImage.PageCount > 0)
							{
								gifImage.RemoveBlock((IGifBlock)gifImage.Pages[0]);
							}
						}

						// add frame
						gifImage.AddPage(sourceImage);
					}
				}
			}
			finally
			{
				if (gifImage != null)
				{
					gifImage.Save();
					gifImage.Dispose();
				}
			}

		}
	}
}

You may find other allowed animation cases and examples here