简体   繁体   English

位图对象不存在于 system.drawing 中?

[英]Bitmap object not present in system.drawing?

I am new to C# and I am trying to create a bitmap object in C# in Visual Studio 2019, but it isn't working.我是 C# 的新手,我试图在 Visual Studio 2019 中的 C# 中创建一个位图对象,但它不起作用。 I have .NET Framework updated to the latest version and I have resharper installed.我已将 .NET Framework 更新到最新版本,并安装了 resharper。 I am using Windows 10.我正在使用 Windows 10。

Ive tried adding the references manually with Add/Reference... and it does not stay checked.我试过使用添加/引用手动添加引用...但它不会保持选中状态。
I added using system.drawing and using system.drawing.common to the top of my code.我将using system.drawingusing system.drawing.common添加到我的代码顶部。
I updated my .net core and enabled it in my project.我更新了我的 .net 核心并在我的项目中启用了它。

using System;
using System.Drawing.Common;

namespace Bot
{
    class Program
    {
        static void Main(string[] args)
        {
            var bmp = new Bitmap();
        }
    }
}

I expected it to create a bitmap object, but it won't compile and gives me errors saying that the bitmap object does not exist in system.drawing .我希望它创建一个位图对象,但它不会编译并给我错误,说system.drawing中不存在位图对象。

It looks like you don't have the package in your system/project.您的系统/项目中似乎没有该软件包。 In you're project directory or from VScode terminal do this:在您的项目目录中或从 VScode 终端执行以下操作:

dotnet add package System.Drawing.Common --version 6.0.0

then add a reference to the package in you're project然后在您的项目中添加对包的引用

Bitmap类是程序集System.Drawing.Common.dll一部分,因此您需要通过 Nuget 包安装System.Drawing.Common

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

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