您的位置:首页 > 其它

自制一个可以为XNA所用的GIF 转 PNG 的小工具

2012-01-03 17:50 176 查看
XNA不支持GIF动画,PNG也需要以平铺的形式

还是郡主:



在我已经有了一些GIF资源的时候,如果能有一个工具可以将GIF转为平铺的PNG就好了

求人不如求已,自己写了一个

[code] using System;


using System.Collections.Generic;


using System.Drawing;


using System.Drawing.Imaging;


using System.IO;


using System.Linq;


using System.Text;


 


namespace GifToPng


{


class Program


    {


static void Main(string[] args)


   {


foreach (var path in args)


       {


Image gif = Image.FromFile(path);


Graphics graphic = null;


var frame = new FrameDimension(gif.FrameDimensionsList[0]);


int count = gif.GetFrameCount(frame);


var image = new Bitmap(gif.Width*count, gif.Height);


for (int i = 0; i < count; i++)


  {


gif.SelectActiveFrame(frame, i);


using (var stream = new MemoryStream())


      {


gif.Save(stream, ImageFormat.Png);


if (graphic == null)


          {


graphic = Graphics.FromImage(image);


}


graphic.DrawImage(new Bitmap(stream), i*gif.Width, 0);


}


}


var splitStr = path.Split('.');


splitStr[splitStr.Length - 1] = "png";


var newPath = string.Join(".", splitStr);


image.Save(newPath);


                 Console.WriteLine("convert success:{0}",newPath);


}


Console.ReadKey();


}


}


}


 

[/code]

使用方法为

将GIF图片拖动到最终生成的EXE上,即可生成对应的PNG图片





该程序可以支持多图片同时处理

以上程序下载:宁珂郡主.rar

--
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐