如何访问 System.Drawing ie System.Drawing.Common in Asp.Net Core 3

How to access System.Drawing ie System.Drawing.Common in Asp.Net Core 3

我正在将以完整框架为目标的 Asp.Net Core 2.2 网站转换为以 .Net Core 3.1 为目标的 Asp.Net Core 3.1 应用程序。我有点不清楚与 System.Drawing 相关的依赖项以及如何实现它们。

我的项目使用 System.Drawing,在 Asp.Net Core 3.1 下编译时出现此错误,提示我添加对 System.Drawing.Common.dll 的引用:

Error CS1069: The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. 1-wwwGiftOasis3 C:\Users\Ron\source\repos\wwwGiftOasis3\wwwGiftOasis3\site\seller\profile\about\s-photos.cs

在 Visual Studio 中,我看不到直接向裸 System.Drawing.Common.dll 添加引用的方法,因此我假设我应该通过 NuGet 添加引用。

在 NuGet 中,我看到一个 System.Drawing.Common 包,它看起来像我想要的,但我不清楚我的项目是否满足依赖项:

我的项目显示了这些依赖项:

所以我有几个与这一切相关的问题:

1) 我的项目依赖框架 Microsoft.NETCore.App 是否满足 NuGet 包的 Microsoft.NETCore.Platforms 依赖?

2) 我只打算 运行 Asp.Net windows 上的 Core 3.1 网站是否满足 NuGet 包的 Microsoft.Win32.SystemEvents 依赖关系?

System.Drawing 使用 Windows 特定的 API,因此与跨平台的 .NET Core 不兼容。 Microsoft 创建了 System.Drawing.Common 作为 .NET Core 的 System.Drawing 的就地替代品。它是一个精确的 API 替换,但在跨平台而不是 Windows 特定的方式中执行图像操作。

总而言之,是的,您只需将 NuGet 放到您的项目中,然后就可以开始了。没有别的你需要担心。