将 RGB 图像转换为灰度 [英] Converting RGB images to grayscale

查看:106
本文介绍了将 RGB 图像转换为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.我是一所大学的学生.是否可以使用 Visual Studio 将 RGB 图像转换为 C# 灰度?

I'm new on programming. I'm a student in a univesity. Is it possible to use visual studio for converting RGB images to grayscale with C#?

有一个包含 RGB jpeg 图像的特定文件夹,并且每天都有新的 jpg 文件.我需要制作一个 exe 文件来将它们转换为灰度.

There is a specific folder that includes RGB jpeg images and every day it has new jpg files too. I need to make an exe file for converting them to grayscale.

我是否必须为这项工作安装新的库,或者 VS2013 的标准库是否足够?

Do I have to install new libraries for this work or are standard libraries of VS2013 enough for this?

推荐答案

标准库就够了.

我曾经用过这个代码:

public static Bitmap GrauwertBild(Bitmap input) 
{
  Bitmap greyscale = new Bitmap(input.Width, input.Height);
  for (int x = 0; x < input.Width; x++)
  {
    for (int y = 0; y < input.Height; y++)
    {
     Color pixelColor = input.GetPixel(x, y);
     //  0.3 · r + 0.59 · g + 0.11 · b
     int grey = (int)(pixelColor.R * 0.3 + pixelColor.G * 0.59 + pixelColor.B * 0.11);
     greyscale.SetPixel(x, y, Color.FromArgb(pixelColor.A, grey , grey , grey ));
    }
  }
  return greyscale;
}

这篇关于将 RGB 图像转换为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆