將 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 ]_
您可以透過以下方式解決此問題:
-
將 runtime.osx.10.10-x64.CoreCompat.System.Drawing NuGet 套件添加到您的 .NET 解決方案中,以在您的專案中包含 libgdiplus。
-
或者,使用以下命令通過 Homebrew 手動安裝該程式庫:
# Update Homebrew and install mono-libgdiplus brew update && brew install mono-libgdiplusSHELL -
更多資訊請參閱官方 .NET 文件。
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。