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

XNA不支持GIF动画,PNG也需要以平铺的形式

还是郡主:image

在我已经有了一些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图片

clip_image001

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

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

--

转载于:https://www.cnblogs.com/chhlgy/archive/2012/01/03/2311176.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值