C#實(shí)現(xiàn)圖像反色的方法
本文實(shí)例講述了C#實(shí)現(xiàn)圖像反色的方法。分享給大家供大家參考。具體如下:
//定義圖像反色函數(shù) private static Bitmap PContray (Bitmap a) { int w = a.Width; int h = a.Height; Bitmap dstBitmap = new Bitmap(a.Width, a.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pOut = (byte*)dstData.Scan0.ToPointer(); byte* p; int stride = srcData.Stride; int r, g, b; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { p = pIn; r = p[2]; g = p[1]; b = p[0]; pOut[2] = (byte)(255 - r); pOut[1] = (byte)(255 - g); pOut[0] = (byte)(255 - b); pIn += 3; pOut += 3; } pIn += srcData.Stride - w * 3; pOut += srcData.Stride - w * 3; } a.UnlockBits(srcData); dstBitmap.UnlockBits(dstData); return dstBitmap; } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#實(shí)現(xiàn)打開指定目錄和指定文件的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)打開指定目錄、打開指定目錄且選中指定文件、打開指定文件,感興趣的小伙伴可以嘗試一下2022-06-06基于Silverlight DataGrid中無代碼設(shè)置開始與結(jié)束日期DatePicker的實(shí)現(xiàn)方法
本篇文章是對(duì)Silverlight DataGrid中無代碼設(shè)置開始與結(jié)束日期DatePicker的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05C# Winform 實(shí)現(xiàn)TCP發(fā)消息
這篇文章主要介紹了C# Winform 實(shí)現(xiàn)TCP發(fā)消息的示例,幫助大家更好的理解和學(xué)習(xí)使用c#技術(shù),感興趣的朋友可以了解下2021-03-03c#數(shù)據(jù)綁定之刪除datatable數(shù)據(jù)示例
這篇文章主要介紹了c#刪除datatable數(shù)據(jù)示例,需要的朋友可以參考下2014-04-04C#實(shí)現(xiàn)進(jìn)程管理的啟動(dòng)和停止實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)進(jìn)程管理的啟動(dòng)和停止方法,以操作記事本程序?yàn)槔?實(shí)例分析了C#針對(duì)進(jìn)程操作的基本技巧,需要的朋友可以參考下2015-07-07C#對(duì)WPF數(shù)據(jù)綁定的菜單插入Seperator分隔
這篇文章介紹了C#對(duì)WPF數(shù)據(jù)綁定的菜單插入Seperator分隔的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06C#實(shí)現(xiàn)Nginx平滑加權(quán)輪詢算法
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)Nginx平滑加權(quán)輪詢算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07