使用 libgdiplus 與 IronOCR:設定指南

This article was translated from English: Does it need improvement?
Translated
View the article in English

.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
# 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

macOS

若您在 macOS 上遇到以下例外情況:

發生未處理的例外。 System.DllNotFoundException:無法從任何名稱中找到或載入原生函式庫:[ libgdiplus, libgdiplus.dylib ]

您可以透過以下方式解決此問題:

# Update Homebrew and install mono-libgdiplus
brew update && brew install mono-libgdiplus
# Update Homebrew and install mono-libgdiplus
brew update && brew install mono-libgdiplus
SHELL
Curtis Chau
技術作家

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

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 6,136,090 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在滾動?

想要快速證明? PM > Install-Package IronOcr
執行範例 觀看您的圖像轉變為可搜尋文字。