Asp.net(C#)-彩色图片转化为黑白

    /// <summary> 
    /// 彩色图片转化为黑白 
    /// </summary> 
    /// <param name="source"></param> 
    /// <returns></returns> 
    public static Bitmap ConvertToGrayscale(Bitmap bitmap) 
    { 
        Bitmap bm = new Bitmap(bitmap.Width, bitmap.Height); 
        for (int y = 0; y < bm.Height; y++) 
        { 
            for (int x = 0; x < bm.Width; x++) 
            { 
                Color c = bitmap.GetPixel(x, y); 
                int rgb = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11); 
                bm.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb)); 
            } 
        } 
        return bm; 
    }
posted @ 2009-09-29 12:45  与时俱进  阅读(574)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈