zoukankan      html  css  js  c++  java
  • png转ico源码

        class Program
        {
            static void Main(string[] args)
            {
                if (args.Length != 1)
                    return;
                string imgName = args[0];
                Console.WriteLine("开始处理...");
                SaveToIcon(imgName);
                Console.WriteLine("处理完毕...");
                return ;
            }
    
            static void SaveToIcon(string srcImg)
            {
                Image img = Image.FromFile(srcImg);
                using(MemoryStream msImg=new MemoryStream(),msIco=new MemoryStream())
                {
                    img.Save(msImg, System.Drawing.Imaging.ImageFormat.Png);
                    using(var bin=new BinaryWriter(msIco))
                    {
                        bin.Write((short)0);
                        bin.Write((short)1);
                        bin.Write((short)1);
    
                        bin.Write((byte)img.Width);
                        bin.Write((byte)img.Height);
                        bin.Write((byte)0);
                        bin.Write((byte)0);
                        bin.Write((short)0);
                        bin.Write((short)32);
                        bin.Write((int)msImg.Length);
                        bin.Write(22);
    
                        bin.Write(msImg.ToArray());
                        bin.Flush();
                        bin.Seek(0, SeekOrigin.Begin);
                        Icon icon = new Icon(msIco);
                        string outputName = Path.Join(Path.GetDirectoryName(srcImg), Path.GetFileNameWithoutExtension(srcImg) + ".ico");
                        using (Stream stream = new FileStream(outputName, FileMode.Create))
                        {
                            icon.Save(stream);
                        }
                    }
                }
            }
        }
    

      

  • 相关阅读:
    (五)Redis在项目中应用
    股票收益最大问题
    (四)redigo
    (三)go-sql-driver
    为什么TCP要3次握手?4次挥手?
    分支预测
    事务隔离级别说明
    剑指offer解题思路锦集11-20题
    C++中的二义性问题
    memcached Vs redis
  • 原文地址:https://www.cnblogs.com/chyshx/p/15103248.html
Copyright © 2011-2022 走看看