在.NET中看不到System.Drawing命名空间中的Image类型

B.S*_*iuk 6 .net c# image dimensions

我正在尝试编写一个程序,通过尺寸对特定文件夹中的图像进行排序,并通过简单的.NET控制台应用程序将小图像移动到另一个文件夹.我决定使用System.Drawing.Image类从图像文件中获取图像尺寸.但我面临以下错误:

找不到类型或命名空间名称"Image"(您是否缺少using指令或程序集引用?)

究竟我做错了什么以及为什么它没有看到这堂课?以下是我的程序的完整代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;

namespace ImageSort
{
    class Program
    {
        static void Main(string[] args)
        {
            string targetPath = @"d:\SmallImages";
            string[] files = Directory.GetFiles(@"d:\Images");
            foreach (string path in files)
            {
                if (File.Exists(path))
                {
                    Image newImage = Image.FromFile(path);
                    var Width = (int)(newImage.Width);
                    var Height = (int)(newImage.Height);
                    if (Width * Height < 660000) {
                        System.IO.File.Move(path, targetPath);
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

feg*_*ter 18

对于 .NET Core 3.1,此问题的答案是只需从 NuGet 安装System.Drawing.Common


Abd*_*HAR 8

您需要添加引用: System.Drawing.dll.

Solution Explorer,右键单击References节点,然后选择添加Reference并查找System.Drawing.dll.