简体   繁体   English

在.NET Core 2.2下的System.Drawing中找不到Image类

[英]Can't find Image class in System.Drawing under .NET Core 2.2

According to the docs , there's supposed to be a class for thumbnail handling in the namespace System.Drawing . 根据文档 ,在命名空间System.Drawing应该有一个用于缩略图处理的类。 I want to create a model that has an image as a property and then save it to a database. 我想创建一个模型,将图像作为属性,然后将其保存到数据库。 However, when I try the code below, I get an error that the class isn't found in that namespace, regardless of the docs stating otherwise. 但是,当我尝试下面的代码时,我得到一个错误,即该命名空间中找不到该类,无论文档是否另有说明。

using System.Drawing;
public class Donkey
{
  public Image Image { get;set; }
}

What am I missing?! 我错过了什么?!

I've googled it but only found old posts and examples that seem not to work . 我用谷歌搜索了它,但只发现旧的帖子示例似乎无法正常工作

Try installing the System.Drawing.Common NuGet package. 尝试安装System.Drawing.Common NuGet包。 This contains Image and other related types like Bitmap . 这包含Image和其他相关类型,如Bitmap

PM> Install-Package System.Drawing.Common

You can also install using the NuGet Package Manager UI accessible by right-clicking the solution in Solution Explorer and choosing Manage NuGet Packages... 您还可以使用NuGet Package Manager UI进行安装,方法是右键单击解决方案资源 管理 中的解决方案,然后选择Manage NuGet Packages ...

System.Drawing.Common

Adding a clarification comment from @KonradViltersten : 添加@KonradViltersten的澄清评论:

Traditionally, System.Drawing was included in the full .NET Framework, but not .NET Core because System.Drawing was based on Windows drawing methods. 传统上, System.Drawing包含在完整的.NET Framework中,但不包含在.NET Core中,因为System.Drawing基于Windows绘图方法。 .NET core was designed to be platform independent and thus did not include anything that was platform specific (like drawing). .NET核心被设计为独立于平台,因此不包含任何特定于平台的内容(如绘图)。 Because this functionality is so requested, MS released a separate assembly that could be installed to provide the functionality 因为要求这个功能,MS发布了一个单独的程序集,可以安装它来提供功能

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

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