How to create animated gif in .NET Core
You should try using Magick.Net which is a good image manipulation library and is also available for .net core. An example of how to create a .gif can be found here.
To add Magick.Net to your .net core project you'll need to modify your project.json as follows:
"dependencies":
{
"Magick.NET.Core-Q8": "7.0.0.0102"
}
Hope this helps!
C# - Create an animated GIF image from selected images in ASP.net
try NGif (A Component written using C#,it provide a way to create gif animations in .NET framework)
this code project article will help you - NGif, Animated GIF Encoder for .NET
Need to create an animated GIF in C#
http://midimick.com/magicknet/
http://midimick.com/magicknet/magickDoc.html
.NET - Creating a looping .gif using GifBitmapEncoder
I finally got this to work after studying this article and referencing the raw bytes of GIF files. If you want to do so yourself, you can get the bytes in hex format using PowerShell like so...
$bytes = [System.IO.File]::ReadAllBytes("C:\Users\Me\Desktop\SomeGif.gif")
[System.BitConverter]::ToString($bytes)
The GifBitmapEncoder appears to write the Header, Logical Screen Descriptor, then the Graphics Control Extension. The "NETSCAPE2.0" extension is missing. In GIFs from other sources that do loop, the missing extension always appears right before the Graphics Control Extension.
So I just plugged in the bytes after the 13th byte, since the first two sections are always this long.
// After adding all frames to gifEncoder (the GifBitmapEncoder)...
using (var ms = new MemoryStream())
{
gifEncoder.Save(ms);
var fileBytes = ms.ToArray();
// This is the NETSCAPE2.0 Application Extension.
var applicationExtension = new byte[] { 33, 255, 11, 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48, 3, 1, 0, 0, 0 };
var newBytes = new List<byte>();
newBytes.AddRange(fileBytes.Take(13));
newBytes.AddRange(applicationExtension);
newBytes.AddRange(fileBytes.Skip(13));
File.WriteAllBytes(saveFile, newBytes.ToArray());
}
How do I use Magick.NET to convert an animated webp image to an animated gif?
A MagickImage
is only a single image. When an animated image is read this will be the first frame. If you want to read all the frames you will need to read the files with a MagickImageCollection
instead.
public void TestConvertImageType() {
using (var animatedWebP = new MagickImageColection("animated.webp")) {
animatedWebP.Write("animated-generated.gif", MagickFormat.Gif);
}
using (var animatedGif = new MagickImageColection("animated.gif")) {
animatedGif.Write("animated-generated.webp", MagickFormat.WebP);
}
}
And you don't need to also install ImageMagick on your machine. The ImageMagick library comes with the Magick.NET library.
Related Topics
Thread Safe C# Singleton Pattern
How to Access an Internal Class from an External Assembly
Why Is "Set as Startup" Option Stored in the Suo File and Not the Sln File
Stop Tabcontrol from Recreating Its Children
How to Change the File Location Programmatically
How to Run a C# Console Application with the Console Hidden
Css, Images, Js Not Loading in Iis
How to Pass Values Across the Pages in ASP.NET Without Using Session
C# Winforms Combobox Dynamic Autocomplete
.Net Hashtable VS Dictionary - Can the Dictionary Be as Fast
How to Find If a Native Dll File Is Compiled as X64 or X86
Why Always Close Database Connection
C# Error: Parent Does Not Contain a Constructor That Takes 0 Arguments
Can Itextsharp.Xmlworker Render Embedded Images
Has Foreach's Use of Variables Been Changed in C# 5
How to Configure the Web.Config to Allow Requests of Any Length