c# 多个图片合成压缩成gif图片的方法

c# 多个图片合成压缩成gif图片的方法

c# gif图片分解成多个图片的方法

using System;
using System.Drawing;
using System.Drawing.Imaging;
using Gif.Components;

namespace Example
{
	class ExampleMain
	{
		[STAThread]
		static void Main(string[] args)
		{
			/* 创建 Gif */
			//you should replace filepath
			String [] imageFilePaths = new String[]{"d:\\01.png","d:\\02.png","d:\\03.png"}; 
			String outputFilePath = "d:\\test.gif";
			AnimatedGifEncoder e = new AnimatedGifEncoder();
			e.Start( outputFilePath );
			e.SetDelay(500);
			//-1:不循环,0:循环播放
			e.SetRepeat(0);
			for (int i = 0, count = imageFilePaths.Length; i < count; i++ ) 
			{
				e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
			}
			e.Finish();
			/* 解压 Gif */
			string outputPath = "d:\\";
			GifDecoder gifDecoder = new GifDecoder();
			gifDecoder.Read( "d:\\test.gif" );
			for ( int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++ ) 
			{
				Image frame = gifDecoder.GetFrame( i );  // frame i
				frame.Save( outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png );
			}
		}
	}
}

网上的一个例子

大家可以下载下来试试

vs2019测试通过

下载源代码

{{collectdata}}

网友评论0