[英]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.