我已将代码移植到.NET Core,并使用了System.Drawing。目前看来,来自corefx的System.Drawing.Common已经支持Linux(请参见此处)。但是我在Linux上运行我的代码时遇到了困难。
特别是我遇到了以下错误:
特别是我遇到了以下错误:
该错误与以下代码有关:NotSupportedException "Could not open display (X-Server required. Check your DISPLAY environment variable)"
Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
之前我遇到了
DllNotFoundException "无法加载 DLL 'libX11': 找不到指定的模块或其某个依赖项。\n (来自 HRESULT: 0x8007007E 的异常)"
并且有以下堆栈跟踪:
at System.Drawing.LibX11Functions.XOpenDisplay(IntPtr display)
at System.Drawing.Graphics.FromHwnd(IntPtr hwnd)
at mycode
但这个问题我通过安装libx11-dev
软件包解决了。
以下是我的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
"无法打开显示器(需要X-Server,请检查您的DISPLAY环境变量)"错误该怎么办?
libgdiplus
及其所有依赖项。总的来说,使用真正的可移植解决方案,如 SkiaSharp,将是一个更好的选择,网址为 https://github.com/mono/SkiaSharp。 - Lex Lilibgdiplus
和他们的System.Drawing
(Microsoft .NET Core 借用了相同的概念)时,从来没有像 Docker 这样的受限环境。Stack Overflow 不能提供太多帮助,因为你需要原始开发者的帮助或自己修改代码库。 - Lex Li