久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

C#getPixel和內(nèi)存法讀取灰度圖信息

 goodwangLib 2018-01-31

getPixel方法:

復(fù)制代碼
private int getPixels(Bitmap bmpobj) { int[,] data = new int[1920, 1200]; int max = 0; for (int i = 0; i < bmpobj.height;="">) { for (int j = 0; j < bmpobj.width;="">) { Color b = bmpobj.GetPixel(j, i); if (max b.R) { max = b.R; } } } return max; }
復(fù)制代碼

 

內(nèi)存法:

復(fù)制代碼
private int GetImgInfo(Bitmap a) { Bitmap src = new Bitmap(a); int w = src.Width; int h = src.Height; int max = 0; BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { byte* p = (byte*)srcData.Scan0; int gray = 0; for (int j = 1; j < h="" -="">1; j++) { for (int i = 1; i < w="" -="">1; i++) { gray = p[0] ;//+= (p[0] + p[1] + p[2]) / 3; p += 4; if (max gray) { max = gray; } } p += srcData.Stride - w * 4; } src.UnlockBits(srcData); return max ; } }
復(fù)制代碼

 根據(jù)數(shù)組畫圖

復(fù)制代碼
private Bitmap drawPic(byte[] srcdata, int width, int height) { // 8bit索引方式位圖,設(shè)置灰度調(diào)色板 var fmt = PixelFormat.Format8bppIndexed; var bmp = new Bitmap(width, height, fmt); var palette = bmp.Palette; for (var i = 0; i <>256; i++) { palette.Entries[i] = Color.FromArgb(i, i, i); } bmp.Palette = palette; // 把數(shù)據(jù)映射到256灰度,,unsafe填充到位圖 var bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, fmt); unsafe { var p = (byte*)bmpData.Scan0; for (var i = 0; i < srcdata.length;="">) { *p = (byte)(srcdata[i]); p++; } } bmp.UnlockBits(bmpData); return bmp; }
View Code
復(fù)制代碼

 根據(jù)灰度圖像讀入一維數(shù)組

復(fù)制代碼
public unsafe byte[] ToArray(Bitmap b) { BitmapData data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat); int height = data.Height; int stride = data.Stride; IntPtr ptr = data.Scan0; int scanBytesLength = stride * height; byte[] rgbValues = new byte[scanBytesLength]; unsafe { Marshal.Copy(ptr, rgbValues, 0, scanBytesLength); } b.UnlockBits(data); return rgbValues; }
復(fù)制代碼

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多