laitimes

Stunned! The image processing library under the .NET platform can process images in this way, which is simply omnipotent

ImageMagick, an image processing universal library under the NET platform

ImageMagick is a free, open-source software suite for editing and manipulating digital images. It can be used to create, edit, composit, or convert bitmap images, and supports a variety of file formats, including JPEG, PNG, GIF, TIFF, and PDF, and it offers a rich API to create, edit, composit, and convert images. ImageMagick natively supports more image processing operations, including but not limited to image format conversion, color space conversion, image filtering, special effects application, etc.

Installation

Polly can be installed via the Nuget package manager:

Install-Package Magick.NET-Q8-AnyCPU           

use

1. Create a simple image

using ImageMagick;

static void CreateSimpleImage()
{
using (MagickImage image = new MagickImage(MagickColor.FromRgb(138, 43, 226), 200, 200))
 {
 image.Write("simple_image.png");
 }
}           

2. Resize the image

static void ResizeImage(string inputImagePath, string outputImagePath, int width, int height)
{
using (MagickImage image = new MagickImage(inputImagePath))
 {
 image.Resize(width, height);
 image.Write(outputImagePath);
 }
}           

3. Crop the image

public void CropImage(string inputImagePath, string outputImagePath, int width, int height, int x, int y)
{
using (MagickImage image = new MagickImage(inputImagePath))
 {
 image.Crop(width, height, x, y);
 image.Write(outputImagePath);
 }
}           

4. Rotate the image

public void RotateImage(string inputImagePath, string outputImagePath, double degrees)
{
using (MagickImage image = new MagickImage(inputImagePath))
 {
 image.Rotate(degrees);
 image.Write(outputImagePath);
 }
}           

5. Blur effect

public void BlurImage(string inputImagePath, string outputImagePath, double radius, double sigma)
{
using (MagickImage image = new MagickImage(inputImagePath))
 {
 image.Blur(radius, sigma);
 image.Write(outputImagePath);
 }
}           

6. Merge multiple images into animated GIFs

public void CreateGifAnimation(string[] imagePaths, string outputGifPath)
{
using (MagickImageCollection collection = new MagickImageCollection())
 {
foreach (var path in imagePaths)
 {
 collection.Read(path);
 }

 collection.AnimationDelay = 100; // 设置动画的延迟时间(单位:1/100秒)
 collection.Write(outputGifPath);
 }
}           

7. Convert the picture to a grayscale image

public void ConvertToGrayscale(string inputImagePath, string outputImagePath)
{
using (MagickImage image = new MagickImage(inputImagePath))
 {
 image.ColorType = ColorType.GRAY;
 image.Write(outputImagePath);
 }
}           

8. Combine two images

public void CompositeImages(string image1Path, string image2Path, string outputImagePath)
{
using (MagickImage image1 = new MagickImage(image1Path))
using (MagickImage image2 = new MagickImage(image2Path))
 {
 image1.Composite(image2, CompositeOperator.Atop);
 image1.Write(outputImagePath);
 }
}           
• 体验地址:https://malus.dotnetshare.com
Stunned! The image processing library under the .NET platform can process images in this way, which is simply omnipotent
  • • 体验地址:https://www.dotnetshare.com
    Stunned! The image processing library under the .NET platform can process images in this way, which is simply omnipotent
加我微信,拉你进全栈进阶、面试交流群,互相监督学习进步等!

❤️ 看完三件事

如果你觉得这篇内容对你挺有启发,我想邀请你帮个小忙:

Read on