.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 @   新*  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示