如何使用二维数组遍历像素? [英] how to loop over the pixels using 2D array?

查看:52
本文介绍了如何使用二维数组遍历像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

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();

推荐答案

根据 pixels 文档,像素是一维数组.所以你可能需要做类似的事情

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

这篇关于如何使用二维数组遍历像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆