1

很抱歉这个虚拟问题,但我是新来的,我找不到答案。

  1. 什么是图像步幅?
  2. 我正在从位帧创建一个缓冲区字节 [](没有问题。)位帧宽度为 1200,位帧高度为 900。所以(我怀疑)缓冲区必须为 1200*900 = 108,0000。但是缓冲区大小是步幅 * 高度 = 432,0000 (4 * 108,0000)。

Stride 计算为bitFrame.PixelWidth * ((bitFrame.Format.BitsPerPixel + 7) / 8); Then I using bitFrame.CopyPixels(pixels, stride, 0); //(byte[] pixels)And I have the function of processing current pixel (that is a struct.)

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

并且还有像素处理功能pixel 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)
  }
}
4

1 回答 1

0

步幅是每行像素的字节数,无论这些像素中有多少是图像的一部分,因此您必须使用步幅来计算基于二维坐标影响的字节:

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; 
}

编辑:我太着急了——根据评论更新答案。

于 2011-11-28T12:17:11.950 回答