在使用.Net Core控制台应用程序中尝试使用System.Drawing时出现错误。

8

我正在尝试在运行于Ubuntu 18.04的.Net Core控制台应用程序中使用System.Drawing.Common创建位图,但是当我执行代码时会显示:

Gdip的类型初始化程序引发了异常。
   在System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)处
   在System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)处
   在MidnightBot.Modules.AdminCommands.CreatePollAsync(String Term1, String Term2, String Description) 位置/home/MidnightBot/Modules/AdminCommands.cs:line 125
System.DllNotFoundException: 无法加载DLL 'libgdiplus':找不到指定的模块。
   在System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()处
   在System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)处
   在System.Drawing.SafeNativeMethods.Gdip..cctor()处

此外,我已经按照这里所述的方法进行了尝试,但并没有成功。

感谢任何帮助。


你只执行了安装依赖的命令吗?这并不足够,实际上除非你是开发库的开发人员,否则不建议这样做。只需使用Ubuntu软件包管理器安装libgdiplus软件包即可。 - NineBerry
看起来好像在构建工件中缺少了那个dll。dotnet restore 可以修复这个问题吗?这应该在编译时就阻止你,而不是在运行时。 - clarkitect
是的,我只是这样做了,那我该如何安装libdigplus?只需使用sudo apt-get install libdigplus命令即可。@NineBerry - Twenty
sudo apt-get install libgdiplus - NineBerry
@NineBerry 没有更多的错误了,图像正在生成,但是有一些奇怪的事情发生,我将更新我的问题。 - Twenty
显示剩余2条评论
1个回答

6
您需要使用软件包管理器安装gdiplus库,例如:
sudo apt-get install libgdiplus

1
@FairyQueen,你尝试过brew install mono-libgdiplus吗? - NineBerry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接