Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I decided to use System.Drawing.Image class to get the image dimentions from an image file. 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?)

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);
                    }
                }
            }
        }
    }
}
like image 557
BohdanZPM Avatar asked May 06 '16 22:05

BohdanZPM


People also ask

Which datatype is used for image in C#?

The following C# program shows how to insert an Image in SQL Server. The following sql script help you to create a table with Image Datatype column. The above script will create a table named as imgtable and define two columns , first column is id ,an integer datatype and second column is image, an image(img) datatype.

Which of the following namespace provides the graphics features?

The System.Drawing Namespace The System. Drawing namespace defines basic GDI+ functionality. This namespace contains the Graphics class, which provides methods for filling and drawing graphics objects.

How do I save a drawing image in C#?

Save(String, ImageCodecInfo, EncoderParameters) Saves this Image to the specified file, with the specified encoder and image-encoder parameters.

What is using system drawing in C#?

The Graphics class provides methods for drawing to the display device. Classes such as Rectangle and Point encapsulate GDI+ primitives. The Pen class is used to draw lines and curves, while classes derived from the abstract class Brush are used to fill the interiors of shapes.


2 Answers

The answer to this issue for .NET Core 3.1 is to simply install System.Drawing.Common from NuGet.

like image 138
feganmeister Avatar answered Oct 15 '22 20:10

feganmeister


You need to add a reference : System.Drawing.dll.

In Solution Explorer, right-click on the References node and choose Add Reference and find System.Drawing.dll.

like image 33
Abdellah OUMGHAR Avatar answered Oct 15 '22 20:10

Abdellah OUMGHAR