完美解决.NET Framework 4.0 中 System.Drawing 库不支持 WebP 格式的图像处理
如果你想在 .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)
-