轉換為 AnyBitmap

若要在 IronSoftware.System.Drawing 中使用或處理任何圖像檔案,所有檔案都必須轉換為 AnyBitmap 檔案。對於來自其他平台的檔案,IronSoftware.System.Drawing 可將這些檔案轉換為 AnyBitmap 檔案。 以下為將其他平台的圖像檔案轉換為 AnyBitmap 檔案的範例。

System.Drawing.Bitmap

來自 System.Drawing 的位圖可轉換為 AnyBitmap 檔案。 首先使用 System.Drawing.Bitmap 從檔案路徑載入 System.Drawing.Bitmap 檔案,接著將該檔案賦值給一個以 AnyBitmap 類型初始化的變數,藉此進行轉換。

System.Drawing.Image

要將 System.Drawing.Image 中的影像進行鑄型轉換,可透過 System.Drawing.Image.FromFile 從檔案路徑載入該檔案,並將其儲存於 AnyBitmap 類型的變數中。

SkiaSharp.SKBitmap

要將 SkiaSharp 中的位圖進行轉換,可透過初始化 SkiaSharp.SKBitmap 變數,並使用 SkiaSharp.SKBitmap.Decode 將從檔案路徑載入的檔案儲存至該變數中。 該檔案隨後可轉換為 AnyBitmap 類型。

SkiaSharp.SKImage

若要載入 SkiaSharp 圖片,請使用 SkiaSharp.SKImage.FromBitmap 從已解碼的 SkiaSharp.SKBitmap 載入檔案,然後將其儲存至 SkiaSharp.SKImage 變數中。 可透過將其賦值給 AnyBitmap 類型的變數,將其轉換為 AnyBitmap 檔案。

SixLabors

可透過 SixLabors.ImageSharp.Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32> 從檔案路徑載入 SixLabors 中的圖片,並將其儲存於 SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32> 變數中。 之後可將其轉換為 AnyBitmap 檔案。

MAUI 圖片

將 MAUI 影像轉換為 AnyBitmap 檔案的功能,僅能在 .NET 4.7.2 以外的環境中執行。 可透過 File.ReadAllBytes 讀取從檔案路徑取得的影像位元組,並將其儲存至 byte[] 陣列中,藉此載入 MAUI 影像檔案。 這些位元組必須使用 Microsoft.Maui.Graphics.Platform.PlatformImage.FromStream 轉換為圖像,然後才能轉換為 AnyBitmap 檔案。

準備開始了嗎?
Nuget 下載 17,121,904 | 版本: 2025.3 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronSoftware.System.Drawing
執行範例 觀看您的 HTML 轉為 PDF。