2011-11-28 27 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