Galosys.Foundation.ImageSharp 26.7.31.1

dotnet add package Galosys.Foundation.ImageSharp --version 26.7.31.1
                    
NuGet\Install-Package Galosys.Foundation.ImageSharp -Version 26.7.31.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.ImageSharp" Version="26.7.31.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.ImageSharp" Version="26.7.31.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.ImageSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.ImageSharp --version 26.7.31.1
                    
#r "nuget: Galosys.Foundation.ImageSharp, 26.7.31.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.ImageSharp@26.7.31.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.ImageSharp&version=26.7.31.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.ImageSharp&version=26.7.31.1
                    
Install as a Cake Tool

Galosys.Foundation.ImageSharp

成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善

基于 SixLabors.ImageSharp 的图像处理扩展库,提供图像加载、缩放、裁剪、格式转换、水印等常用功能。

功能概览

1. 图像加载与保存

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;

// 加载图像
using var image = await Image.LoadAsync("input.jpg");

// 保存为不同格式
await image.SaveAsync("output.png", new PngEncoder());
await image.SaveAsync("output.webp", new WebpEncoder { Quality = 80 });

2. 图像缩放

// 按比例缩放
image.Mutate(ctx => ctx.Resize(new ResizeOptions
{
    Size = new Size(800, 600),
    Mode = ResizeMode.Max
}));

// 指定宽高缩放(保持比例)
image.Mutate(ctx => ctx.Resize(400, 0)); // 宽度400,高度自适应

3. 图像裁剪

// 裁剪指定区域
image.Mutate(ctx => ctx.Crop(new Rectangle(100, 100, 400, 400)));

// 从中心裁剪
image.Mutate(ctx => ctx.Resize(new ResizeOptions
{
    Size = new Size(200, 200),
    Mode = ResizeMode.Crop
}));

4. 图像旋转与翻转

// 旋转指定角度
image.Mutate(ctx => ctx.Rotate(90));
image.Mutate(ctx => ctx.RotateRounded(45));

// 翻转
image.Mutate(ctx => ctx.FlipHorizontal());
image.Mutate(ctx => ctx.FlipVertical());

5. 添加水印

using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.Fonts;

// 添加文字水印
var font = SystemFonts.Get("Arial", 12);
image.Mutate(ctx => ctx.DrawText("Galosys", font, Color.White, new PointF(10, 10)));

// 添加图片水印
using var watermark = await Image.LoadAsync("logo.png");
image.Mutate(ctx => ctx.DrawImage(watermark, 0.5f));

6. 图像滤镜

using SixLabors.ImageSharp.Processing;

// 灰度
image.Mutate(ctx => ctx.Grayscale());

// 模糊
image.Mutate(ctx => ctx.GaussianBlur(5));

// 锐化
image.Mutate(ctx => ctx.GaussianSharpen(3));

// 亮度调整
image.Mutate(ctx => ctx.Brightness(1.2f));

// 对比度调整
image.Mutate(ctx => ctx.Contrast(1.1f));

7. 格式转换

// 获取图像信息(不加载完整图像)
var imageInfo = await Image.IdentifyAsync("input.jpg");
Console.WriteLine($"Width: {imageInfo.Width}, Height: {imageInfo.Height}");

// 转换为 Base64
using var ms = new MemoryStream();
await image.SaveAsPngAsync(ms);
var base64 = Convert.ToBase64String(ms.ToArray());

8. 生成缩略图

public static async Task<byte[]> GenerateThumbnailAsync(byte[] source, int width, int height)
{
    using var input = new MemoryStream(source);
    using var image = await Image.LoadAsync(input);
    
    image.Mutate(ctx => ctx.Resize(new ResizeOptions
    {
        Size = new Size(width, height),
        Mode = ResizeMode.Crop
    }));
    
    using var output = new MemoryStream();
    await image.SaveAsJpegAsync(output, new JpegEncoder { Quality = 80 });
    return output.ToArray();
}

安装

<PackageReference Include="Galosys.Foundation.ImageSharp" Version="x.x.x" />

目录结构

Galosys.Foundation.ImageSharp/
└── (依赖 SixLabors.ImageSharp 库)

依赖

  • SixLabors.ImageSharp
  • SixLabors.ImageSharp.Drawing
  • Galosys.Foundation.Core
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.7.31.1 34 7/31/2026
26.7.30.1 31 7/30/2026
26.7.29.1 61 7/29/2026
26.7.28.1 75 7/28/2026
26.7.26.2 85 7/26/2026
26.7.26.1 81 7/25/2026
26.7.25.1 87 7/25/2026
26.7.24.2 90 7/24/2026
26.7.24.1 84 7/24/2026
26.7.22.1 93 7/23/2026
26.7.21.1 91 7/21/2026
26.7.20.2 81 7/20/2026
26.7.20.1 86 7/20/2026
26.7.19.3 84 7/19/2026
26.7.19.2 87 7/19/2026
26.7.19.1 89 7/19/2026
26.7.18.2 84 7/18/2026
26.7.18.1 91 7/18/2026
26.7.17.1 91 7/17/2026
26.7.14.1 96 7/14/2026
Loading failed