将彩色照片变成黑白照片

From: http://www.cnblogs.com/jillzhang/archive/2006/10/09/524571.html
学习
1 /// <summary>
 2        /// 将彩色图片变成黑白色的照片
 3        /// </summary>
 4        /// <param name="image">原来图片</param>
 5        /// <returns>返回的黑白照片</returns>
 6        public static Bitmap WhiteAndBlack(System.Drawing.Bitmap image)
 
7        {
 
8            //原来图片的长度
 9            int width = image.Width;
10            //原来图片的高度
11            int height = image.Height;
12            //改变色素
13            //横坐标
14            for (int x = 0; x < width; x++)
15            {
16                //纵坐标
17                for (int y = 0; y < height; y++)
18                {
19                    //获得坐标(x,y)颜色
20                    Color color = image.GetPixel(x, y);
21                    //获得该颜色下的黑白色
22                    int value = (color.R + color.G + color.B) / 3;
23                    //设置颜色
24                    image.SetPixel(x,y,Color.FromArgb(value, value, value));
25                }

26            }

27            return image;
28        }

posted @ 2006-10-11 15:19  jhtchina  阅读(768)  评论(1)    收藏  举报