標籤:負數 stat ftp lin none 12px inter static 參考
本文執行個體講述了C#彩色圖片灰階化實現方法。分享給大家供大家參考。具體方法如下:
主要功能代碼如下:
代碼如下:
public static Bitmap MakeGrayscale(Bitmap original)
{
//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#彩色圖片灰階化演算法執行個體
本文地址: http://www.paobuke.com/develop/c-develop/pbk23444.html
相關內容關於C#串連FTP時路徑問題的解決方案C#自訂日誌記錄C#實現Ruby的負數索引器C#實現擷取不同對象中名稱相同屬性的方法
C#實現漢字轉拼音或轉拼音首字母的方法C#?D???3??èí?tê?·?ò?°2×°êμ??′ú??·??íC#自訂序列化ISerializable的實現方法C#實現的序列化通用類執行個體
C#彩色圖片灰階化演算法執行個體