how to loop over the pixels using 2D array?

泄露秘密 提交于 2019-12-11 03:52:51

问题


For example:

loadPixels(); 
for (int i = 0; i < 240; i++) 
{
  for(int j =0; i < 240; j++)
  {
    color p = 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();

回答1:


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).



来源:https://stackoverflow.com/questions/5315265/how-to-loop-over-the-pixels-using-2d-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!