灰度图像 [英] Grayscale Imge
本文介绍了灰度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注此链接:
http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
I am following this link:
http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
public static Bitmap MakeGrayscale(Bitmap original)
{
//make an empty bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
for (int i = 0; i < original.Width; i++)
{
for (int j = 0; j < original.Height; j++)
{
//get the pixel from the original image
Color originalColor = original.GetPixel(i, j);
//create the grayscale version of the pixel
int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
+ (originalColor.B * .11));
//create the color object
Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);
//set the new image''s pixel to the grayscale version
newBitmap.SetPixel(i, j, newColor);
}
}
return newBitmap;
}
I AM PASSING VALUES TO THIS METHOD AS:
protected void grayscale_Click(object sender, EventArgs e)
{
//Get the path of image file
string path = Image1.ImageUrl;
//create bitmap from path and pass as argument to function makegryscale2
Bitmap b = MakeGrayscale(new Bitmap(path.Substring(2)));
//overwrite with saving at same path
b.Save(path);
//set it imageurl
Image1.ImageUrl = path;
}
但是它给我一个错误,该错误表明参数无效.请让我知道如何使用此方法????
BUT it is giving me an error, the error says Invalid Parameter. plz let me know how can i use this method????
推荐答案
哪一行出现此错误?
您必须在未传递正确值的情况下调用grayscale_Click
.
Which line are you getting this error in?
You cannot callgrayscale_Click
without passing in the right values.
这篇关于灰度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文