你的位置:首页 > ASP.net教程

[ASP.net教程]asp.net(c#)将彩色图片变灰阶图片


代码如下:

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.using System.Drawing;using System.Drawing.Imaging;/* 何问起 hovertree.com */namespace WebApplication2{  public partial class _Default : System.Web.UI.Page  {    protected void Page_Load(object sender, EventArgs e)    {      Bitmap b = new Bitmap(Server.MapPath("01.jpg"));      for (int x = 0; x < b.Width; x++)      {        for (int y = 0; y < b.Height; y++)        {          Color pixel = b.GetPixel(x, y);          int val = (pixel.R + pixel.G + pixel.B) / 3;          b.SetPixel(x, y, Color.FromArgb(val, val, val));        }      }      b.Save(Server.MapPath("1.jpg"));    }  }}

推荐:http://www.cnblogs.com/roucheng/p/3518068.html