我有一個(2448 * 2048)5Mpixel圖像數(shù)據(jù)的數(shù)據(jù),但該圖片框只有(816 * 683)約500,000像素,因此我降低了像素,只需要一個黑白圖像,所以我使用了G值創(chuàng)建圖像,但是我輸出的圖像如下圖所示。我的錯誤是哪一部分? public int[,] lowered(int[,] greenar) { int[,] Sy = new int[816, 683]; int x = 0; int y = 0; for (int i = 1; i < 2448; i += 3) { for (int j = 1; j < 2048; j += 3) { Sy[x, y] = greenar[i, j]; y++; } y = 0; x++; } return Sy; }static Bitmap Create(int[,] R, int[,] G, int[,] B) { int iWidth = G.GetLength(1); int iHeight = G.GetLength(0); Bitmap Result = new Bitmap(iWidth, iHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Rectangle rect = new Rectangle(0, 0, iWidth, iHeight); System.Drawing.Imaging.BitmapData bmpData = Result.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); IntPtr iPtr = bmpData.Scan0; int iStride = bmpData.Stride; int iBytes = iWidth * iHeight * 3; byte[] PixelValues = new byte[iBytes]; int iPoint = 0; for (int i = 0; i < iHeight; i++) { for (int j = 0; j < iWidth; j++) { int iG = G[i, j]; int iB = G[i, j]; int iR = G[i, j]; PixelValues[iPoint] = Convert.ToByte(iB); PixelValues[iPoint + 1] = Convert.ToByte(iG); PixelValues[iPoint + 2] = Convert.ToByte(iR); iPoint += 3; } } System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes); Result.UnlockBits(bmpData); return Result; }
2 回答

慕運維8079593
TA貢獻1876條經(jīng)驗 獲得超5個贊
您無需對圖像進行降采樣,就可以通過這種方式進行。將picturebox屬性BackgroundImageLayout設(shè)置為zoom或Stretch并將其分配為:
picturebox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
picturebox.BackgroundImage = bitmap;
System.Windows.Forms.ImageLayout.Zoom將自動將位圖調(diào)整為圖片框的大小。
- 2 回答
- 0 關(guān)注
- 196 瀏覽
添加回答
舉報
0/150
提交
取消