开发者

how to loop over the pixels using 2D array?

For example:

loadPixels(); 
for (int i = 0; i < 240; i++) 
{
  for(int j =0; i < 240; j++)
  {
    color p =开发者_如何学Go pixels[i][j];    // ERROR : The type of the expression must be an array 
                                  type but it resolved to int


    float cRed = 0.2989 * red(p);
    float cGreen = 0.5870 * green(p); 
    float cBlue = 0.1140 * blue(p);
    pixels[i][j] = color(cRed, cGreen, cBlue);
  }
}
updatePixels();


According to the pixels documentation, pixels is a one dimensional array. So you'll probably need to do something like

int row = i;
int col = j;
int offset = row * width + col;
color p = pixels[offset];

Not sure how you get the width of the window, but that's what you'd need to do (assuming that the rows are stored in order in the array).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜