所以我使用了一个我在网络上找到的东西的变体来将图像转换成灰度。我希望能够“淡入灰色”,即渐进式地淡出颜色,这样我就可以从全色到部分颜色再到纯灰色。
public static ColorMatrix ColorMatrixForGrayScale = new ColorMatrix(new[] {
new[] {.3f, .3f, .3f, 0, 0},
new[] {.59f, .59f, .59f, 0, 0},
new[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1} });
public static Bitmap MakeGrayscale(Image original, int percent = 100)
{
ColorMatrix matrix = GetMatrix(percent); // returns a variation of the above.
//create a blank bitmap the same size as original
var newBitmap = new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
var g = System.Drawing.Graphics.FromImage(newBitmap);
//create some image attributes
var attributes = new ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(matrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
return newBitmap;
}所以问题有两个部分。首先,我可以使用矩阵吗?如果是,我有什么不同,如果不是,什么是可行的方法?我正在考虑创建全灰度,然后将其与彩色图像合并(一些方法)。
谢谢
编辑:原始源Switch on the code
发布于 2012-06-10 16:22:44
为了改变饱和度,http://www.codeproject.com/Tips/78995/Image-colour-manipulation-with-ColorMatrix上有一篇有趣的文章
https://stackoverflow.com/questions/10964179
复制相似问题