.net Core Group Pictures by Resolution

1.Open VSCode

2.Open Terminal by using 'Ctrl+J'

3.dotnet new console

4.dotnet add package System.Drawing.Common

5.Open Program.cs

code

using System;
using System.Drawing;
using System.IO;
namespace CheckPic {
   class Program {
       //按照分辨率分组照片
       static void Main (string[] args) {
           Console.WriteLine ("Please Input The Folder FullName:");
           var path = Console.ReadLine ();
           DirectoryInfo di = new DirectoryInfo (path);
           FileInfo[] files = di.GetFiles ();
           foreach (var item in files) { 
               var strFilePath = item.FullName;
               Image pic = System.Drawing.Image.FromFile (strFilePath); //strFilePath是该图片的绝对路径
               int intWidth = pic.Width; //长度像素值
               int intHeight = pic.Height; //高度像素值  
               var newPath = path + @"\" + intWidth + "x" + intHeight + @"\";
               if (!Directory.Exists (newPath))
                   Directory.CreateDirectory (newPath);
               if (!File.Exists (newPath + item.Name)) {
                   Console.WriteLine ("Copy to " + newPath + item.Name + ".....");
                   File.Copy (item.FullName, newPath + item.Name);
               } else {
                   Console.WriteLine ("The File \"" + newPath + item.Name + "\"  already exists!");
               }
           }
       }
   }
}

6.dotnet run

posted @ 2022-03-23 13:55  新*  阅读(27)  评论(0编辑  收藏  举报