C#彩色圖片灰度化算法實例
本文實例講述了C#彩色圖片灰度化實現(xiàn)方法。分享給大家供大家參考。具體方法如下:
主要功能代碼如下:
{
//create a blank bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
//create some image attributes
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//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;
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案
這篇文章主要介紹了C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案,需要的朋友可以參考下2014-07-07C#中Convert.ToInt32()和int.Parse()的區(qū)別介紹
Convert是一個類,繼承自system.Object;int是值類型,在本文為大家詳細(xì)介紹下它與int.Parse()的區(qū)別,感興趣的朋友可以參考下2013-10-10C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色
這篇文章主要介紹了C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色,需要的朋友可以參考下2017-09-09C# 使用HttpClient上傳文件并附帶其他參數(shù)的步驟
這篇文章主要介紹了C# 使用HttpClient上傳文件并附帶其他參數(shù)的步驟,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-12-12