Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using .net core with C# on linux, lib System.Drawing is missing

Error message

Program.cs(1,14): error CS0234: The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?

Is it possible to fix that? Or I am not meant to be using this library, if I am developing on Linux with C#?

like image 252
Daniel Avatar asked Jan 03 '23 22:01

Daniel


2 Answers

2021:

Quote from System.Drawing.Common only supported on Windows, Recommended action:

To use these APIs for cross-platform apps, migrate to one of the following libraries:

  • ImageSharp
  • SkiaSharp
  • Microsoft.Maui.Graphics

You are able to use System.Drawing for the short term but be aware there is no support.

Alternatively, you can enable support for non-Windows platforms by setting the System.Drawing.EnableUnixSupport runtime configuration switch to true in the runtimeconfig.json file:

This configuration switch was added to give cross-platform apps that depend heavily on this package time to migrate to more modern libraries. However, non-Windows bugs will not be fixed. In addition, we may completely remove support for non-Windows platforms in a future release, even if you enable it using the runtime configuration switch.

To be able to use System.Drawing on Linux machines, you might also need to install libgdiplus as mentioned by @saman-azadi and @alex-from-jitbit.


2017:

The System.Drawing namespace is at the moment not part of corefx as it relies on the GDI+ features from Windows.

But there are plans to support it in the future.


But there are multiple alternatives:

CoreCompat.System.Drawing

CoreCompat.System.Drawing is a .NET Core port of the Mono implementation of System.Drawing. Like System.Drawing in .NET Framework and in Mono, CoreCompat.System.Drawing also relies on GDI+ on Windows. Caution is therefore advised, for the same reasons.

ImageSharp

ImageSharp is a brand new, pure managed code, and cross-platform image processing library. Its performance is not as good as that of libraries relying on native OS-specific dependencies, but it remains very reasonable. Its only dependency is .NET itself, which makes it extremely portable: there is no additional package to install, just reference ImageSharp itself, and you’re done.

Magick.NET

Magick.NET is the .NET wrapper for the popular ImageMagick library. ImageMagick is an open-source, cross-platform library that focuses on image quality, and on offering a very wide choice of supported image formats. It also has the same support for EXIF as ImageSharp.

(The .NET Core build of Magick.NET currently only supports Windows.)

SkiaSharp

SkiaSharp is the .NET wrapper for Google’s Skia cross-platform 2D graphics library, that is maintained by the Xamarin team. SkiaSharp is now compatible with .NET Core, and is extremely fast.

FreeImage-dotnet-core

This library is to the native FreeImage library what Magick.NET is to ImageMagick: a .NET Core wrapper. It offers a nice choice of image formats, good performance, and good visual quality.


Here are some good examples and performance analyses of the libraries mentioned above.

like image 76
NtFreX Avatar answered Feb 01 '23 07:02

NtFreX


Run the following command on the command line

sudo apt-get install libgdiplus

or

sudo yum install -y libgdiplus-2.10-9.el7.x86_64
like image 31
Saman Azadi Avatar answered Feb 01 '23 06:02

Saman Azadi