/// <summary>
/// 灰度图像处理
/// </summary>
public class GrayPic
{
/// <summary>
/// 获取pic图像对应的黑白图像
/// </summary>
/// <param name="pic"></param>
/// <param name="NumGray">像素灰度值</param>
/// <returns></returns>
public static Bitmap ToBlack(Bitmap pic, int NumGray = 220)
{
// 灰度图像转化为黑白图像
if (isGrayPic(pic))
{
Color Black = Color.FromArgb(255, 0, 0, 1);
Color White = Color.FromArgb(255, 255, 255, 254);
Bitmap tmp = new Bitmap(pic.Width, pic.Height);
for (int h = 0; h < pic.Height; h++)
{
for (int w = 0; w < pic.Width; w++)
{
Color C = pic.GetPixel(w, h);
Color D = (C.R < NumGray && C.G < NumGray && C.B < NumGray) ? Black : White;
tmp.SetPixel(w, h, D);
灰度图像转化为黑白图像、转化图像为一位位深度的图像(仅保留黑色)
于 2024-03-01 10:05:55 首次发布