using System;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
class Program
{
static void Main()
{
// 创建一个Bitmap对象,加载图像文件
Bitmap image = new Bitmap("input.jpg");
// 创建灰度滤镜
Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
// 应用滤镜到图像
Bitmap grayImage = grayscaleFilter.Apply(image);
// 保存处理后的图像
grayImage.Save("output.jpg");
Console.WriteLine("图像已成功转换为灰度并保存。");
}
}
AForge 和 AForge.Imaging 是 AForge.NET 框架的核心命名空间,提供了丰富的图像处理功能。Bitmap 类加载一张名为 input.jpg 的图像文件。Grayscale 类用于将彩色图像转换为灰度图像。构造函数中的参数表示红、绿、蓝通道的权重。Apply 方法将灰度滤镜应用到原始图像上,生成新的灰度图像。output.jpg 文件。如果你需要更复杂的图像处理功能,AForge.NET 框架还提供了许多其他类和方法供你使用。
下一篇:c# webrtc
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站