国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#圖像偽彩色處理方法

2020-01-24 01:56:04
字體:
來源:轉載
供稿:網友

本文實例講述了C#圖像偽彩色處理方法。分享給大家供大家參考。具體如下:

//灰度圖轉偽彩色圖像函數public Bitmap PGrayToColor(Bitmap src){  try  {   Bitmap a = new Bitmap(src);   Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);   System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);   int stride = bmpData.Stride;   unsafe   {     byte* pIn = (byte*)bmpData.Scan0.ToPointer();     byte* P;     int R, G, B;     int temp = 0;     for (int y = 0; y < a.Height; y++)     {     for (int x = 0; x < a.Width; x++)     {       P = pIn;       B = P[0];       G = P[1];       R = P[2];       temp = (byte)(B * 0.114 + G * 0.587 + R * 0.299);       if (temp >= 0 && temp <= 63)       {        P[2] = 0;        P[1] = (byte)(254 - 4 * temp);        P[0] = (byte)255;       }       if (temp >= 64 && temp <= 127)       {        P[2] = 0;        P[1] = (byte)(4 * temp - 254);        P[0] = (byte)(510 - 4 * temp);       }       if (temp >= 128 && temp <= 191)       {        P[2] = (byte)(4 * temp - 510);        P[1] = (byte)(255);        P[0] = (byte)0;       }       if (temp >= 192 && temp <= 255)       {        P[2] = (byte)255;        P[1] = (byte)(1022 - 4 * temp);        P[0] = (byte)0;       }       pIn += 3;     }     pIn += stride - a.Width * 3;     }   }   a.UnlockBits(bmpData);   return a;  }  catch (Exception e)  {   MessageBox.Show(e.Message.ToString());   return null;  }}

原圖:

效果圖:

反色圖:

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆化县| 博湖县| 自贡市| 桦川县| 古田县| 聂拉木县| 邵武市| 安岳县| 龙井市| 中宁县| 锦州市| 海安县| 襄垣县| 崇义县| 吴堡县| 拉萨市| 曲麻莱县| 吉木乃县| 米林县| 麻城市| 昌吉市| 集贤县| 安平县| 张掖市| 政和县| 增城市| 嘉义市| 乌恰县| 山阴县| 池州市| 新蔡县| 卫辉市| 济阳县| 嵊泗县| 南澳县| 米泉市| 海兴县| 黄山市| 绿春县| 西宁市| 镇沅|