2011-11-28 28 views
1

對不起虛擬問題,但我是新來的,我找不到答案。圖像處理(一般)

  1. 什麼是圖像跨度?
  2. 我從Bitframe創建一個緩衝區字節[](沒有問題)。位幀寬度是1200,位幀高度是900.所以(正如我懷疑的)緩衝區必須是1200 * 900 = 108,0000。 但是緩衝區大小是stride * height = 432,0000(4 * 108,0000)。

步幅作爲bitFrame.PixelWidth * ((bitFrame.Format.BitsPerPixel + 7)/8); 然後我使用bitFrame.CopyPixels(pixels, stride, 0); //(byte[] pixels)計算我有處理當前象素的函數(即是一個結構。)

struct pixel { 
    float r; 
    float g; 
    float b; 
}; 

而且也有像素處理功能像素processPixel(int x, int y)。我怎麼能用我的緩衝區使用這個功能?我認爲它必須以某種方式被稱爲像這樣:

for(int i = 0; i < height; i++) { 
    for(int j = 0; j < height; j++) { 
    processPixel(i, j); 
    // But how could I use this function with my byte[] buffer? 
    // And what exactly in this buffer? 
    // (why stride*height = 4*width*height? cause there are 3 values for pixel RGB) 
    } 
} 
+0

我剛剛搜索了一下「image stride」,第一次打擊看起來相當不錯,有沒有什麼具體的你找不到? –

+0

謝謝。我剛剛發現這個問題的第二部分呢? – curiousity

回答

0

步幅是每行像素的字節數,無論怎麼樣的像素的多少是圖像的一部分,所以你必須在計算哪些字節使用步幅影響基於2-d座標:

void processPixel(int x, int y) 
{ 
    // This is if your image format is 4 bytes per pixel such as RGBA 
    int startByteIndex = x * 4 + y * stride; 
} 

編輯:我太沖 - 答案更新基於意見。

+1

您的代碼與您的正確描述不符。它應該是x * 4 + y *步幅。 –

+0

是漢斯是對的 – curiousity

+0

感謝您的支持/更正。我擔心我可能沒有努力確保代碼的正確性,但我希望有人會在有問題時糾正我。很高興看到它按我所希望的方式運作。 – BlueMonkMN