简体   繁体   English

在控制台应用程序下找不到 System.drawing 命名空间

[英]System.drawing namespace not found under console application

I selected console application as my C# project.我选择控制台应用程序作为我的 C# 项目。 But the imports that seemed to work under Windows Form project don't seem to work here.但是似乎在 Windows 窗体项目下工作的导入在这里似乎不起作用。 It says that the drawing namespace does not exist.它说绘图命名空间不存在。

using System.Drawing;
using System.Drawing.Imaging;

My problem is that I need to have the bitmap class.我的问题是我需要有位图类。 I am trying to make a command line app that does bitmap manipulations to a image.我正在尝试制作一个对图像进行位图操作的命令行应用程序。 That's why I didn't choose my project to be a Windows Form one.这就是为什么我没有将我的项目选择为 Windows Form one。

You need to add a reference to System.Drawing.dll .您需要添加对System.Drawing.dll的引用。

As mentioned in the comments below this can be done as follows: In your Solution Explorer (Where all the files are shown with your project), right click the "References" folder and find System.Drawing on the .NET Tab.正如下面的评论中提到的,这可以按如下方式完成:在您的解决方案资源管理器中(所有文件都显示在您的项目中),右键单击“参考”文件夹并在 .NET 选项卡上找到 System.Drawing。

在此处输入图片说明

在此处输入图片说明

  1. Add using System.Drawing;添加使用 System.Drawing;
  2. Go to solution explorer and right click on references and select add reference转到解决方案资源管理器并右键单击引用并选择添加引用
  3. Click on assemblies on the left单击左侧的程序集
  4. search for system.drawing搜索 system.drawing
  5. check system.drawing检查系统图
  6. Click OK单击确定
  7. Done完毕

If you are using Visual Studio 2010 or plus then check the target framework that is it .Net Framework 4.0 or .Net Framework 4.0 Client Profile.如果您使用的是 Visual Studio 2010 或 plus,请检查目标框架是 .Net Framework 4.0 或 .Net Framework 4.0 Client Profile。 then change is to .Net Framework 4.0.然后更改为 .Net Framework 4.0。

You need to add reference this .dll file (System.Drawing.dll) to perform drawing operations.您需要添加引用此 .dll 文件 (System.Drawing.dll) 以执行绘图操作。

If it is OK then follow these steps to add reference to System.Drawing.dll如果没问题,请按照以下步骤添加对System.Drawing.dll引用

  1. In Solution Explorer , right-click on the project node and click Add Reference.Solution Explorer ,右键单击project node并单击Add Reference.
  2. In the Add Reference dialog box, select the tab indicating the type of component you want to reference.在“添加引用”对话框中,选择指示要引用的组件类型的选项卡。
  3. Select the System.Drawing.dll to reference, then click OK.选择要引用的System.Drawing.dll ,然后单击“确定”。

For,Adding System.Drawing Follow some steps: Firstly, right click on the solution and click on add Reference.对于,添加 System.Drawing 遵循一些步骤: 首先,右键单击解决方案,然后单击添加引用。 Secondly, Select the .NET Folder.其次,选择 .NET 文件夹。 And then double click on the Using.System.Drawing;然后双击 Using.System.Drawing;

安装包 System.Drawing.Common

Add reference .dll file to project.将参考 .dll 文件添加到项目。 Right, Click on Project reference folder --> click on Add Reference -->.Net tab you will find System.Drawing --> click on ok this will add a reference to System.Drawing右键,单击项目引用文件夹 --> 单击添加引用 --> .Net 选项卡,您将找到 System.Drawing --> 单击确定,这将添加对 System.Drawing 的引用

Install this library from Nuget从 Nuget 安装这个库

System.Drawing.Common

https://www.nuget.org/packages/System.Drawing.Common/6.0.0 https://www.nuget.org/packages/System.Drawing.Common/6.0.0

  1. Right click on properties of Console Application.右键单击控制台应用程序的属性。
  2. Check Target framework检查Target framework
  3. If it is .Net framework 4.0 Client Profile then change it to .Net Framework 4.0如果是.Net framework 4.0 Client Profile则将其更改为.Net Framework 4.0

It works now它现在有效

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM