25

I want to make a Class Library (.NET Standard) and I'm using System.Drawing,

but I get the error:

CS0246 C# The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)

I'm using .NET Standard 2.0.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
IIRawCodeII
  • 375
  • 1
  • 3
  • 9
  • GDI / System.Drawing (where Bitmap lives) simply isn't available in .NET Core, thus not in .NET Standard, either. Progress on porting to Core is here: https://github.com/dotnet/corefx/issues/20325 – vcsjones Oct 13 '17 at 04:16
  • using System.Windows.Media.Imaging; – Kaval Patel Oct 13 '17 at 04:52

2 Answers2

43

I'm the author of CoreCompat.System.Drawing. If you're on .NET Core 2.0, I'd recommend you'd move to System.Drawing.Common instead, which is the Microsoft-maintained implementation of System.Drawing for .NET Core.

If you're on Linux or macOS, make sure to install libgdiplus. On macOS, run brew install mono-libgdiplus; on Linux your package manager should provide you with a libgdiplus package.

Frederik Carlier
  • 4,606
  • 1
  • 25
  • 36
  • I think `CoreCompat.System.Drawing` is still useful if one wants to deploy a pure .NET Standard dependent library. A question: could the dependency of `CoreCompat.System.Drawing` be lowered to just .NET Standard 1.2? This allow it to be compatible also with .NET Framework 4.5 – ceztko Nov 04 '18 at 10:36
26

Update

As of last month (May 2018), Microsoft have a production release (previously it was preview/RC) of System.Drawing.Common, a NuGet package which supersedes both versions of the CoreCompat.System.Drawing package. This should be used going forwards.

For those using docker

You also need the libgdiplus library within your final docker image, as System.Drawing.Common relies on this. You can install that using the following Dockerfile command:

RUN apt-get update \
    && apt-get install -y libgdiplus libc6-dev \
    && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll \
    && ln -s /usr/lib/x86_64-linux-gnu/libdl.so /lib64/libdl.so.2 \
    && ln -s /usr/lib/x86_64-linux-gnu/libdl.so /lib64/libdl.so

Old answer

For now you can use the CoreCompat.System.Drawing nuget package.

We've been using it in production code for a few months (drawing on video screencaps) and it has been working great. It's basically a slot-in replacement for System.Drawing.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • 1
    I've installed the NuGet Package but I can't access its reference. How come? – IIRawCodeII Oct 14 '17 at 00:24
  • 1
    It turns out I don't need to add CoreCompat. Thanks! – IIRawCodeII Oct 14 '17 at 17:11
  • @IIRawCodeII I just wanted to point out that I've found out in the past few days that there is a CoreCompat.System.Drawing.v2 library available now if you're using a new enough version of .NET Core. Unfortunately I'm using it on AWS' Lambda so I'll have to wait :) – ProgrammingLlama Oct 20 '17 at 05:31