小弟其实是一个爱玩Image processing的人....
今天就介绍如何用asp.net(c#)来做影像处理的程式..
输入彩色图片..输出灰阶图片.这个其实很简单.就是将RGB三原色..相加除以3
把结果再填回去RGB的位置..就可以做到了...
例如:R=50,G=100,B=30, R+G+B=50+100+30=180/3 = 90
所以:R=90,G=90,B=90...以此类推..
imageprocess.aspx.cs
- using ...System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing;
- using System.Drawing.Imaging;
-
- public partial class imageprocess : System.Web.UI.Page
- ...{
- protected void Page_Load(object sender, EventArgs e)
- ...{
- Bitmap b = new Bitmap(Server.MapPath("f6.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("Newf6.jpg"));
-
- }
- }