c# nuget包_本周的NuGet软件包:ImageProcessor-C#中的轻量级图像处理

本文介绍了ImageProcessor,一个开源的C#库,用于实时处理图像,支持调整大小、旋转、裁剪等多种操作。该库还提供Web缓存功能,减轻服务器压力,并可以通过其流畅API轻松实现功能串联。作者鼓励社区参与项目,贡献力量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c# nuget包

c# nuget包

I really enjoy image manipulation in code. Sure, resizing photos is fun in Photoshop, but there's something viscerally enjoyable when you change images with your own code.

我真的很喜欢用代码进行图像处理。 当然,在Photoshop中调整照片的大小很有趣,但是当您使用自己的代码更改图像时,会有一些特别有趣的事情。

I've talked about image resizing libraries like ImageResizer before, but there's certainly room for more than one. Today I want to showcase ImageProcessor, an open source "collection of lightweight libraries written in C# that allows you to manipulate images on-the-fly using .NET 4+." ImageProcessor is available on GitHub.

我之前已经讨论过像ImageResizer这样的图像调整大小的库,但是肯定有不止一个的空间。 今天,我想展示ImageProcessor ,这是一个开源的“用C#编写的轻量级库集合,它允许您使用.NET 4+即时操作图像。ImageProcessor在GitHub上可用

ImageProcessor methods include; Resize, Rotate, Rounded Corners, Flip, Crop, Watermark, Filter, Saturation, Brightness, Contrast, Quality, Format, Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.

ImageProcessor方法包括; 调整大小,旋转,圆角,翻转,裁切,水印,滤镜,饱和度,亮度,对比度,质量,格式,晕影,高斯模糊,高斯锐化和透明度。

ImageProcessor has a notable number of configuration options for web apps, and a supporting ImageProcessor.Web package as well. It's an impressive body of work.

ImageProcessor具有大量用于Web应用程序的配置选项,并且还具有支持的ImageProcessor.Web软件包。 这是令人印象深刻的工作。

I like this simple example of loading, resizing, and saving an image with their fluent API:

我喜欢这个使用流畅的API加载,调整大小和保存图像的简单示例:

// Read a file and resize it.
byte[] photoBytes = File.ReadAllBytes(file);
int quality = 70;
ImageFormat format = ImageFormat.Jpeg;
Size size = new Size(150, 0)

using (MemoryStream inStream = new MemoryStream(photoBytes))
{
using (MemoryStream outStream = new MemoryStream())
{
using (ImageFactory imageFactory = new ImageFactory())
{
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.Resize(size)
.Format(format)
.Quality(quality)
.Save(outStream);
}

// Do something with the stream.
}
}

You can easily chain functions with the API, like tinting and constraning:

您可以轻松地使用API链接函数,例如着色和约束:

imageFactory.Load(inStream)
.Constrain(size)
.Tint(Color.FromArgb(255, 106, 166, 204))
.Format(format)
.Save(outStream);

When you add ImageProcessor.Web it adds caching that takes pressure off your web servers. You can easily add HttpHandlers to watermark an image, for example, and cache the result.

添加ImageProcessor.Web时,它会添加缓存,从而减轻Web服务器的压力。 例如,您可以轻松地添加HttpHandlers来对图像加水印并缓存结果。

This is a library that has as a lot of potential. Since it's open source, I'm sure they'd appreciate help from the community! Personally, I think they could use more Unit Tests and more examples.

这是一个潜力巨大的图书馆。 由于它是开源的,我相信他们会感谢社区的帮助! 我个人认为他们可以使用更多的单元测试和更多的示例。

Head over to https://github.com/JimBobSquarePants/ImageProcessor and star this project! Get involved, file issues, and contribute! http://imageprocessor.org/

前往https://github.com/JimBobSquarePants/ImageProcessor并为该项目加注星标! 参与进来,提出问题并做出贡献! http://imageprocessor.org/

相关链接 (Related Links)

翻译自: https://www.hanselman.com/blog/nuget-package-of-the-week-imageprocessor-lightweight-image-manipulation-in-c

c# nuget包

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值