Java 从整数中获取二维数组位置

Java 从整数中获取二维数组位置,java,math,multidimensional-array,processing,pixel,Java,Math,Multidimensional Array,Processing,Pixel,我正在从图像中加载像素。 对于我检查颜色并创建图像的每个像素,我现在想将此图像添加到二维数组中 int MAPWIDTH = 64; // in pixels int MAPHEIGHT = 16; // in pixel PImage[][] forGroundMap; PImage file = loadImage(path); file.loadPixels(); int size = file.width * file.height; for (int

我正在从图像中加载像素。 对于我检查颜色并创建图像的每个像素,我现在想将此图像添加到二维数组中

int MAPWIDTH = 64; // in pixels
int MAPHEIGHT = 16; // in pixel
PImage[][] forGroundMap;

PImage file = loadImage(path);


file.loadPixels();
   
   int size = file.width * file.height;
   
   for (int i = 0; i < size; i++) {

    int y = divideBy(i, MAPWIDTH);

    //forGroundMap[y][x] == something what is x and y here
   }
}


但是,这并没有返回行中的列,我不确定这是否有效,以及如何继续前进。

您似乎想要的是简单的除法运算

int y = 1 / 64;
System.out.println (y);
y = 65 / 64;
System.out.println (y);
编辑

要获得x值,请使用模

int x = 1 / 64;
int y = 1 % 64;
System.out.printf ("you are at [%d,%d]%n", x,y);
x = 65 / 64;
y = 65 % 64;
System.out.printf ("you are at [%d,%d]%n", x,y);

PImage image
根本没有被使用。不确定你在问什么,但是
MAPWIDTH
的值是多少,假设你有一个包含行和collumn的大表,但你只知道你所在行的行数*collumn。我需要知道我在哪一行和哪一行。我们把那些不属于问题的东西处理掉,因为根据你的代码和你的帖子,你不可能猜到你在问什么。我不想表现得刻薄,但在当前格式下却无能为力。我编辑了代码,我需要知道2d数组的行和列,因为我只有像素位置的数字。我检查了图像中的每个像素,我想设置2d阵列中的每个像素。这并不能解决x轴的问题。我认为我的divideBy方法已经正确地完成了y。我需要x变量。如果我的方法按预期工作。是的,它应该是简单的除法,我真的不知道这里的数学是什么
int x = 1 / 64;
int y = 1 % 64;
System.out.printf ("you are at [%d,%d]%n", x,y);
x = 65 / 64;
y = 65 % 64;
System.out.printf ("you are at [%d,%d]%n", x,y);