首页 > 其他 > 详细

图片转黑白的简单办法

时间:2016-06-26 16:43:38      阅读:223      评论:0      收藏:0      [点我收藏+]

使用原像素点RGB的平均值即可

 1 public Image BlackAndWhite(Image image)
 2         {
 3             int Height = image.Height;
 4             int Width = image.Width;
 5             Bitmap newPic = new Bitmap(Width,Height);
 6             Bitmap oldPic = (Bitmap)image;
 7             Color pixel;
 8 
 9             for (int x = 0; x < Width; x++)
10             {
11                 for (int y = 0; y < Height; y++)
12                 {
13                     pixel = oldPic.GetPixel(x, y);
14                     int r, g, b, result = 0;
15                     r = pixel.R;
16                     g = pixel.G;
17                     b = pixel.B;
18                     result = (r + g + b) / 3;
19                     newPic.SetPixel(x, y, Color.FromArgb(result,result,result));
20                 }
21             }
22 
23             return newPic;
24         }

 

图片转黑白的简单办法

原文:http://www.cnblogs.com/zhaotianff/p/5617983.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!