将 libgdiplus 与 IronOCR 结合使用:设置指南
Curtis Chau
更新: 2026年8月2日
.NET Core需要libgdiplus才能使用Microsoft System.Drawing.Common NuGet包。 如果在 macOS 或 Linux 系统上找不到该组件,您可能会遇到以下异常:
- 未处理的异常。 System.DllNotFoundException:无法找到或加载任何名称的本机库:[ libgdiplus, libgdiplus.so ]_
- 如果您看到
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception,,请阅读我们的NET6中的System.Drawing.Common指南。
Linux
Ubuntu、Debian
要在 Ubuntu 或 Debian 上安装所需的库,请运行以下命令:
# Update package lists and install necessary libraries
sudo apt-get update && sudo apt-get install -y apt-utils libgdiplus libc6-dev
SHELL
Docker
在您的 Dockerfile 中添加以下行,以确保必要的库包含在您的 Docker 镜像中:
# Update package lists and install necessary libraries in Docker container
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
Dockerfile
macOS
如果您在 macOS 上遇到以下异常:
未处理的异常。 System.DllNotFoundException:无法找到或加载任何名称的本机库:[ libgdiplus, libgdiplus.dylib ]_
您可以通过以下方式解决此问题:
-
向您的.NET解决方案中添加runtime.osx.10.10-x64.CoreCompat.System.Drawing NuGet包以在您的项目中包含libgdiplus。
-
或者,可以通过以下命令使用Homebrew手动安装该库:
# Update Homebrew and install mono-libgdiplus brew update && brew install mono-libgdiplusSHELL -
可以在官方.NET文档中找到更多信息。
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。