【问题标题】:Cannot see the Image type in System.Drawing namespace in .NET在 .NET 的 System.Drawing 命名空间中看不到图像类型
【发布时间】:2016-09-02 02:48:05
【问题描述】:

我正在尝试编写一个程序,该程序按尺寸对特定文件夹中的图像进行排序,并通过简单的 .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);
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# .net image dimensions


    【解决方案1】:

    您需要添加参考:System.Drawing.dll.

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

    【讨论】:

    • 是的,它有帮助!我在这方面是个新手。谢谢!
    • 这对于一个菜鸟来说帮助太大了。
    猜你喜欢
    • 2022-07-06
    • 1970-01-01
    • 2011-08-26
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    相关资源
    最近更新 更多