如果你想在 .NET Framework 4.0 中使用 ImageMagick 處理圖片,可以通過 Magick.NET
庫來實現。Magick.NET
是 ImageMagick 的 .NET 封裝,可以用來讀取、寫入、編輯圖像。
以下是如何使用 Magick.NET 來處理圖像并提取圖像的寬度和高度。
步驟:
-
安裝 Magick.NET: 首先,你需要在項目中安裝
Magick.NET
庫。在 NuGet Package Manager Console 中運行:Install-Package Magick.NET-Q8-AnyCPU -Version 7.12.0
-
示例代碼: 使用
Magick.NET
來讀取圖像并獲取其寬度和高度。using ImageMagick;public void ProcessImage(string filePath) {using (MagickImage image = new MagickImage(filePath)){// 獲取圖像的格式string format = image.Format.ToString();// 處理圖像(例如獲取寬度、高度等)int width = image.Width;int height = image.Height;// 輸出圖像的格式和尺寸Console.WriteLine($"Image Format: {format}, Width: {width}, Height: {height}");} }
MagickImage
(通過 Magick.NET)支持非常多種常見的圖像格式。ImageMagick 本身是一個功能強大的圖像處理工具,支持超過 100 種圖像格式。以下是一些常見的圖像格式,MagickImage
支持的主要格式:
常見的圖像格式:
-
位圖圖像格式:
-
.bmp
(Bitmap) -
.gif
(Graphics Interchange Format) -
.png
(Portable Network Graphics) -
.jpg
或.jpeg
(JPEG) -
.tiff
(Tagged Image File Format) -
.webp
(WebP) -
.heif
/.heic
(High Efficiency Image Format)
-
-
矢量圖像格式:
-
.svg
(Scalable Vector Graphics) -
.eps
(Encapsulated PostScript) -
.ai
(Adobe Illustrator) -
.pdf
(Portable Document Format) -
.pdfx
(PDF/X formats)
-
-
RAW 圖像格式:
-
.cr2
(Canon RAW 2) -
.nef
(Nikon RAW) -
.dng
(Digital Negative) -
.orf
(Olympus RAW) -
.rw2
(Panasonic RAW) -
.arw
(Sony RAW)
-
-
動畫圖像格式:
-
.gif
(Animated GIF) -
.apng
(Animated PNG) -
.webp
(Animated WebP) -
.mng
(Multiple-image Network Graphics)
-
-
特殊圖像格式:
-
.ico
(Windows Icon) -
.cur
(Windows Cursor) -
.pdf
(Portable Document Format) -
.xpm
(X PixMap) -
.tga
(Targa) -
.hdr
(High Dynamic Range Imaging)
-