I have code ported onto .NET Core that uses System.Drawing. Currently it seems System.Drawing.Common from corefx supports Linux. But I have difficulties with running my code on Linux.
Particularly I'm getting:
NotSupportedException "Could not open display (X-Server required. Check your DISPLAY environment variable)"
for this code:
Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
Previously I was getting
DllNotFoundException "Unable to load DLL 'libX11': The specified module or one of its dependencies could not be found.\n (Exception from HRESULT: 0x8007007E)"
with stacktrace:
at System.Drawing.LibX11Functions.XOpenDisplay(IntPtr display)
at System.Drawing.Graphics.FromHwnd(IntPtr hwnd)
at mycode
But this issue I fixed by installing libx11-dev
package.
Here's my Dockerfile:
FROM microsoft/aspnetcore
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true
# install libgdiplus for System.Drawing
RUN apt-get update && \
apt-get install -y --allow-unauthenticated libgdiplus libc6-dev
# install x11 for System.Drawing
RUN apt-get update && \
apt-get install -y --allow-unauthenticated libx11-dev
So what can I do with "Could not open display (X-Server required. Check your DISPLAY environment variable)" error?
Perhaps, you can use an image-based Graphics
, rather than an window-based. Something like this:
var g = Graphics.FromImage(new Bitmap(1, 1));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With