Re: [問題] 灰階圖片的width和widthstep

看板C_and_CPP作者 (燒)時間13年前 (2012/03/19 21:57), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/4 (看更多)
※ 引述《Arim (Arim5566)》之銘言: : 應該要把上述的程式碼改成 : for (int i = 0; i < height;i++) : for (int j = 0; j < widthStep-(widthStep-width*nchannel); j++) { : Img->imageData[i*widthStep+j]=0; //將整張圖用1-dim的方式表示 : } : 其中 widthStep-width*nchannel=因為align而多出來的byte : 也就是widthStep-(多出來的byte)=真正的ImageData : 但是我在網路上沒看過有這樣的寫法@@,幾乎都是第1種居多 : 執行結果看起來是沒問題的 : 不知道我這樣的寫法是否正確? 試想 1366x768 width = 1366 1366*3 = 4098 不為四的倍數 向上補齊到4100 widthStep = 4100 所以蠢點寫就: widthStep = width*3; if (widthStep != (widthStep/4)*4 ) widthStep = (widthStep/4 + 1)*4; 寫漂亮點就 widthStep = ((width*3 + 3)/4)*4; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 180.176.120.10
文章代碼(AID): #1FPpjKbL (C_and_CPP)
文章代碼(AID): #1FPpjKbL (C_and_CPP)