2014-01-08 34 views
-1

我寫爲顯示Y1(亮度)這個代碼在圖片框顯示:圖像不是在圖片框

R = new byte [width, height];// R,G,B not empty contain data 

G = new byte [width, height]; 

B = new byte [width, height]; 

Y1 = new double[width, height]; 

Bitmap bmp4 = new Bitmap(width, height); 
Int32 zz; 

for (int x = 0; x < width; x++) 

for (int y = 0; y < height; y++) 
{ 

    Y1[x, y] = (0.39 * R[x,y]) + (0.59 * G[x,y]) + (0.12 * B[x,y]); 

    zz = Convert.ToInt32(Y1[x, y]); 

    bmp4.SetPixel(x, y, Color.FromArgb(zz )); 
} 

當我執行此代碼圖片框空不顯示圖像,爲什麼? 這個代碼在C#和圖像的類型是位圖

+1

重複的[this](http://stackoverflow.com/questions/20974290/display-double-array-in-picturebox?rq=1)和[this](http://stackoverflow.com/questions/ 20978085/convert-each-location-from-array-of-double-rq = 1)並且可能[this](http://stackoverflow.com/questions/20974290/display-double-array-in- picturebox?rq = 1) – venerik

+0

@ venerik-雖然它的複製,但在那些問題沒有答案..所以這個問題是正確的... ... –

回答

0

我還沒有完全有時間看這個,但問題似乎是你將字節轉換爲顏色(設置每個像素爲Color.Red ,例如,工作正常)。

當然,我也假設你正在你的代碼之後調用此:

picturebox.Image = bmp4; 

Color.FromArgb預計INT32還含有阿爾法數據,我懷疑是你的問題所在。