简体   繁体   English

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

[英]Cannot see the Image type in System.Drawing namespace in .NET

I'm trying to write a program that sorts images in specific folder by ther dimensions and moves little images to another folder via simple .NET console application. 我正在尝试编写一个程序,通过尺寸对特定文件夹中的图像进行排序,并通过简单的.NET控制台应用程序将小图像移动到另一个文件夹。 I decided to use System.Drawing.Image class to get the image dimentions from an image file. 我决定使用System.Drawing.Image类从图像文件中获取图像尺寸。 But I face following error: 但我面临以下错误:

The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly referrence?) 找不到类型或命名空间名称“Image”(您是否缺少using指令或程序集引用?)

What exactly did I do wrong and why it doesn't see this class? 究竟我做错了什么以及为什么它没有看到这堂课? Here are the complete code of my program: 以下是我的程序的完整代码:

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);
                    }
                }
            }
        }
    }
}

You need to add a reference : System.Drawing.dll. 您需要添加一个引用: System.Drawing.dll.

In Solution Explorer , right-click on the References node and choose Add Reference and find System.Drawing.dll . Solution Explorer ,右键单击References节点并选择Add Reference并找到System.Drawing.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 wpf 应用程序的命名空间“System.Drawing”中找不到类型“Icon” - The type 'Icon' could not be found in the namespace 'System.Drawing' in wpf application .NET 核心与系统.绘图 - .NET Core and System.Drawing System.Drawing命名空间中不存在Point - Point does not exist in namespace System.Drawing 使用.net中的System.Drawing创建一个Captcha - Working with System.Drawing in .net to create a Captcha System.Drawing Image.FromFile - System.Drawing Image.FromFile 无法从程序集&#39;System.Drawing,Version = 4.0.0.0的加载类型&#39;System.Drawing.Font&#39;加载类型 - Cannot load type from load type 'System.Drawing.Font' from assembly 'System.Drawing, Version=4.0.0.0 aspnetVnext核心CLR中缺少System.Drawing命名空间 - System.Drawing namespace missing in aspnetVnext core CLR 在控制台应用程序下找不到 System.drawing 命名空间 - System.drawing namespace not found under console application 错误 CS7069 对类型“图像”的引用声称它是在“System.Drawing”中定义的,但无法找到 - Error CS7069 Reference to type 'Image' claims it is defined in 'System.Drawing', but it could not be found 在.NET Core 2.2下的System.Drawing中找不到Image类 - Can't find Image class in System.Drawing under .NET Core 2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM