嗨,我想每12分钟重复一次 image
像素如果像素是黑色的,我想在我的数组上加1,否则加0。
int width = image.getWidth();
int height = image.getHeight();
int[][] pixels = new int[height / 12][width / 12];
int counterX = 1;
int counterY = 1;
for (int i = 0; i < width / 12; i++) {
for (int j = 0; j < height / 12; j++) {
if (counterX == 1 && counterY == 1) {
int rgb = image.getRGB(counterX, counterY);
String s = Integer.toHexString(rgb);
if (s.equals("ff000000")) {
pixels[i][j] = 1;
} else {
pixels[i][j] = 0;
}
counterX += 12;
} else {
int rgb = image.getRGB(counterX, counterY);
String s = Integer.toHexString(rgb);
if (s.equals("ff000000")) {
pixels[i][j] = 1;
} else {
pixels[i][j] = 0;
}
counterX += 12;
if (counterX > width) {
counterX = 1;
counterY += 12;
if (counterY > height) {
counterY = height;
}
}
}
}
}
return pixels;
我的索引41超出了长度41的界限,它发生在这一行 pixels[i][j] = 0;
x有点问题。
暂无答案!
目前还没有任何答案,快来回答吧!