如何将位图图像转换为黑色和白色的C#? [英] How to convert a bitmap image to black and white in c#?

查看:177
本文介绍了如何将位图图像转换为黑色和白色的C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
转换图像为黑白或棕褐在C#

我正在写一个C#应用程序,打开图像,点击一个按钮,显示它只有黑色和白色!
我肯定能找到很多在网络上的信息,但我的搜索没有给我很多的理解和有用的信息。

I'm writing a C# application, that opens an image, and clicking on a button, displays it in only black and white! I was sure to find a lot of information on the net, but my searches didn't give me a lot of understandable and useful information.

我有不知道如何着手。没有任何一个有什么建议吗?知道在网络上的教程?

I have no idea of how to proceed. Does any one have any advice ? Know a tutorial on the net?

推荐答案

有一次,我发现,转换位图以灰度功能

I once found a function that converts a bitmap to grayscale

public Bitmap GrayScale(Bitmap Bmp)
{
    int rgb;
    Color c;

    for (int y = 0; y < Bmp.Height; y++)
    for (int x = 0; x < Bmp.Width; x++)
    {
        c = Bmp.GetPixel(x, y);
        rgb = (int)((c.R + c.G + c.B) / 3);
        Bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
    }
    return Bmp;
}



该函数接受位图作为参数,并且它在灰度返回位

The function accepts a bitmap as a parameter, and it returns the bitmap in grayscale.

我希望这有助于。

这篇关于如何将位图图像转换为黑色和白色的C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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