IronBarcode - Alternative to System.Drawing.Common

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

Iron Softwareは、IronDrawingという名前の_System.Drawing.Common_のオープンソースの代替を提供しています。 IronDrawingについて詳しくは、こちらをクリックしてください。

.NET 6から、System.Drawing.Common はWindows上でのみ動作します

  • 非 Windows オペレーティングシステムでは、ランタイム構成スイッチを設定しない限り、PlatformNotSupportedException を内包エクスセプションとした TypeInitializationException がスローされます。
  • .NET 6では、コード参照が非Windowsオペレーティングシステム用にコンパイルされるとき、プラットフォームアナライザーはコンパイル時に警告を発します。 さらに、設定オプションを設定しない限り、次のランタイムエクスセプションがスローされます:
System.TypeInitializationException : The type initializer for 'Gdip' threw an exception.
          ---- System.PlatformNotSupportedException : System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
Stack Trace:
            at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromFile(String filename, IntPtr& bitmap)
          /_/src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs(42,0): at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
          /_/src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs(25,0): at System.Drawing.Bitmap..ctor(String filename)
          /_/src/libraries/System.Resources.ResourceManager/tests/ResourceManagerTests.cs(270,0): at System.Resources.Tests.ResourceManagerTests.EnglishImageResourceData()+MoveNext()
          /_/src/libraries/System.Linq/src/System/Linq/Select.cs(136,0): at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
----- Inner Stack Trace -----
          /_/src/libraries/System.Drawing.Common/src/System/Drawing/LibraryResolver.cs(31,0): at System.Drawing.LibraryResolver.EnsureRegistered()
          /_/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs(65,0): at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
          /_/src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs(27,0): at System.Drawing.SafeNativeMethods.Gdip..cctor()

一時的な回避策: runtimeconfig.json ファイルの System.Drawing.EnableUnixSupport ランタイム構成スイッチを true に設定することで非Windowsプラットフォームのサポートを有効化します。

{
  "runtimeOptions": {
    "configProperties": {
      "System.Drawing.EnableUnixSupport": true
    }
  }
}

このソリューションは、.NET 6 での System.Drawing サポートにおけるMicrosoftの現行ソリューションです: https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 1,935,276 | バージョン: 2025.11 ただ今リリースされました