完美解决.NET Framework 4.0 中 System.Drawing 库不支持 WebP 格式的图像处理

如果你想在 .NET Framework 4.0 中使用 ImageMagick 处理图片,可以通过 Magick.NET 库来实现。Magick.NET 是 ImageMagick 的 .NET 封装,可以用来读取、写入、编辑图像。

以下是如何使用 Magick.NET 来处理图像并提取图像的宽度和高度。

步骤:

  1. 安装 Magick.NET : 首先,你需要在项目中安装 Magick.NET 库。在 NuGet Package Manager Console 中运行:

    cs 复制代码
    Install-Package Magick.NET-Q8-AnyCPU -Version 7.12.0
  2. 示例代码 : 使用 Magick.NET 来读取图像并获取其宽度和高度。

    cs 复制代码
    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 支持的主要格式:

常见的图像格式:

  1. 位图图像格式

    • .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)

  2. 矢量图像格式

    • .svg (Scalable Vector Graphics)

    • .eps (Encapsulated PostScript)

    • .ai (Adobe Illustrator)

    • .pdf (Portable Document Format)

    • .pdfx (PDF/X formats)

  3. RAW 图像格式

    • .cr2 (Canon RAW 2)

    • .nef (Nikon RAW)

    • .dng (Digital Negative)

    • .orf (Olympus RAW)

    • .rw2 (Panasonic RAW)

    • .arw (Sony RAW)

  4. 动画图像格式

    • .gif (Animated GIF)

    • .apng (Animated PNG)

    • .webp (Animated WebP)

    • .mng (Multiple-image Network Graphics)

  5. 特殊图像格式

    • .ico (Windows Icon)

    • .cur (Windows Cursor)

    • .pdf (Portable Document Format)

    • .xpm (X PixMap)

    • .tga (Targa)

    • .hdr (High Dynamic Range Imaging)

相关推荐
TomCode先生3 分钟前
c#动态树形表达式详解
开发语言·c#
上位机付工9 小时前
C#与倍福TwinCAT3进行ADS通信
开发语言·c#
土了个豆子的10 小时前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
疯狂的维修10 小时前
c#中public类比博图
c#·自动化
土了个豆子的12 小时前
03.缓存池
开发语言·前端·缓存·visualstudio·c#
许泽宇的技术分享13 小时前
重新定义音频编程:SoundFlow如何以模块化设计革新.NET音频开发生态
.net·音视频
步步为营DotNet1 天前
5-2EFCore性能优化
数据库·性能优化·.net
xiaowu0801 天前
策略模式-不同的鸭子的案例
开发语言·c#·策略模式