自制一个可以为XNA所用的GIF 转 PNG 的小工具
XNA不支持GIF动画,PNG也需要以平铺的形式
在我已经有了一些GIF资源的时候,如果能有一个工具可以将GIF转为平铺的PNG就好了
求人不如求已,自己写了一个
1: using System;
2: using System.Collections.Generic;
3: using System.Drawing;
4: using System.Drawing.Imaging;
5: using System.IO;
6: using System.Linq;
7: using System.Text;
8:
9: namespace GifToPng
10: {
11: class Program
12: {
13: static void Main(string[] args)
14: {
15: foreach (var path in args)
16: {
17: Image gif = Image.FromFile(path);
18: Graphics graphic = null;
19: var frame = new FrameDimension(gif.FrameDimensionsList[0]);
20: int count = gif.GetFrameCount(frame);
21: var image = new Bitmap(gif.Width*count, gif.Height);
22: for (int i = 0; i < count; i++)
23: {
24: gif.SelectActiveFrame(frame, i);
25: using (var stream = new MemoryStream())
26: {
27: gif.Save(stream, ImageFormat.Png);
28: if (graphic == null)
29: {
30: graphic = Graphics.FromImage(image);
31: }
32: graphic.DrawImage(new Bitmap(stream), i*gif.Width, 0);
33: }
34: }
35: var splitStr = path.Split('.');
36: splitStr[splitStr.Length - 1] = "png";
37: var newPath = string.Join(".", splitStr);
38: image.Save(newPath);
39: Console.WriteLine("convert success: {0}",newPath);
40: }
41: Console.ReadKey();
42: }
43: }
44: }
45:
使用方法为
将GIF图片拖动到最终生成的EXE上,即可生成对应的PNG图片
该程序可以支持多图片同时处理
以上程序下载:宁珂郡主.rar
--
逍遥地羊啊。。。。