小弟其實是一個愛玩Image processing的人....
今天就介紹如何用asp.net(c#)來做影像處理的程式..
輸入彩色圖片..輸出灰階圖片.這個其實很簡單.就是將RGB三原色..相加除以3
把結果再填回去RGB的位置..就可以做到了...
小弟其實是一個愛玩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"));
}
}
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"));
}
}
執行結果: