Search code examples
c#bitmapsystem.drawingclass-library

Cannot find Bitmap Class in Class Library (.NET Standard)


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.


Solution

  • 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.