Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

c# - 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. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try installing the System.Drawing.Common NuGet package. This contains Image and other related types like 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...

System.Drawing.Common

Adding a clarification comment from @KonradViltersten:

Traditionally, System.Drawing was included in the full .NET Framework, but not .NET Core because System.Drawing was based on Windows drawing methods. .NET core was designed to be platform independent and thus did not include anything that was platform specific (like drawing). Because this functionality is so requested, MS released a separate assembly that could be installed to provide the functionality


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...