处理 - 图像阵列错误 - "类型不匹配,'处理.core.PImage'不匹配.."

时间:2017-06-09 03:51:11

标签: java arrays image processing type-mismatch

我试图将图片加载到void setup()中的数组中,但是当我这样做时会给我这个错误:"类型不匹配,'处理.core.PImage&# 39;不匹配' processing.core.PImage'。知道这意味着什么以及如何解决它?这是我的简化代码:

PImage [] goodCandy = new PImage [3];
int rand=(int) (2*Math.random()) +1;

void setup() {
for (int i=0; i<goodCandy.length; i++) {
  goodCandy = loadImage ("goodCandy" + i + ".png");
}
}
void draw() {
if (current=="play") {
loadStuff();
}
}
void loadStuff() {
image(goodCandy[rand], 0, 0, 50, 50);
}

我基本上想要从数组生成一个随机糖果并让它出现,但我得到了这个错误。我在名为goodCandy1,2,3png的文件夹中有3个图像。任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

goodCandy[i] = loadImage("goodCandy" + i + ".png");

由于您尝试将PImage存储在PImage[]中,因此发生了不匹配。 请记住,loadImage()会返回PImage而不是PImage的数组,即PImage[]