使用 libgdiplus 與 IronOCR:設定指南
Curtis Chau
Updated: 2026年6月29日
.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
Text
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-libgdiplus
SHELL
- 更多資訊請參閱官方 .NET 文件。

技術作家
Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。
...
閱讀更多