Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 595
Konrad Viltersten Avatar asked Jan 23 '19 21:01

Konrad Viltersten


Video Answer


1 Answers

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

like image 105
Martin Zikmund Avatar answered Oct 17 '22 01:10

Martin Zikmund