C#彩色圖片灰度化算法實(shí)例
本文實(shí)例講述了C#彩色圖片灰度化實(shí)現(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;
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法
- C#圖片上傳效果實(shí)例分析
- C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法分析
- C#給圖片加水印的簡(jiǎn)單實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)在服務(wù)器端裁剪圖片的方法
- C#使用Socket上傳并保存圖片的方法
- C#實(shí)現(xiàn)的圖片、string相互轉(zhuǎn)換類分享
- C#識(shí)別出圖片里的數(shù)字和字母
- c#實(shí)現(xiàn)抓取高清美女妹紙圖片
- C#實(shí)現(xiàn)將Email地址轉(zhuǎn)成圖片顯示的方法
相關(guān)文章
C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案
這篇文章主要介紹了C# KeyUp事件中MessageBox的回車(Enter)鍵回調(diào)問題解決方案,需要的朋友可以參考下2014-07-07C#中Convert.ToInt32()和int.Parse()的區(qū)別介紹
Convert是一個(gè)類,繼承自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