Ejemplo n.º 1
0
 static byte[] TinyPasswordByte = BitConverter.GetBytes(TinyPasswordInt);    //密码缓存
 //开始压缩图片
 public static void TinyPng(string path, DirectoryInfo theFolder)
 {
     if (theFolder == null)
     {
         theFolder = new DirectoryInfo(@path);
     }
     //遍历文件
     foreach (FileInfo NextFile in theFolder.GetFiles())
     {
         string strType = NextFile.Extension.ToLower();
         if (strType == ".png" || strType == ".jpg") //只判断图片
         {
             var fileData = NextFile.OpenRead();
             //读取密码
             fileData.Seek(-8, SeekOrigin.End);
             fileData.Read(ulongRead, 0, 8);
             fileData.Close();
             if (TinyPasswordInt != System.BitConverter.ToUInt64(ulongRead, 0))
             {
                 //没找到密码说明是新的
                 TinyCmdList.Add("./pngquant/pngquant " + Util.config.TinyParm + " " + NextFile.FullName + " --ext .png --force --skip-if-larger");
                 TinyFileList.Add(NextFile.FullName, (int)NextFile.Length);
             }
         }
     }
     //遍历文件夹
     foreach (DirectoryInfo NextFolder in theFolder.GetDirectories())
     {
         TinyPng(NextFolder.FullName, NextFolder);
     }
 }