如何解决图像数组 - 得到相同的错误
每当我编写此代码时:
PImage[] flowers=new PImage[3];
Bubble[] bubbles=new Bubble[5];
void setup() {
size(640,360);
for(int i=0; i<flowers.length; i++){
flowers[i]=loadImage(“flower”+i+".jpg");
}
for(int i=0; i<bubbles.length; i++){
int index=int(random(0,flowers.length));
bubbles[i]=new Bubble(flowers[index],100+i*100,300,random(32,72));
}
}
void draw() {
background(255);
for (int i=0; i<bubbles.length; i++){
bubbles[i].display();
bubbles[i].ascend();
bubbles[i].top();
}
}
AND CLASS:
class Bubble {
float x;
float y;
float diameter;
PImage img;
Bubble(PImage tempImg,float tempX,float tempY,float tempD) {
x=tempX;
y=tempY;
diameter=tempD;
img=tempImg;
}
void display() {
stroke(0);
fill(127);
image(img,x,y,diameter,diameter);
}
void ascend() {
y–;
x=x+random(-2,2);
}
void top() {
if (y<diameter/2) {
y=diameter/2;
}
}
}
我总是收到错误消息:“文件“flower0.jpg”丢失或无法访问,请确保 URL 有效或文件已添加到您的草图并且可读。 文件“flower1.jpg”丢失或无法访问,请确保 URL 有效或该文件已添加到您的草图中并且是可读的。 文件“flower2.jpg”丢失或无法访问,请确保 URL 有效或该文件已添加到您的草图中且可读。 空指针异常 无法运行草图(目标虚拟机初始化失败)。 有关更多信息,请阅读修订版.txt 和帮助?故障排除。''
尽管我已经仔细检查了我保存图像的方式和位置(名称等),但我仍然无法解决这个问题。
解决方法
Processing 有一种非常简单的方法可以让您访问本地文件,而不必过多担心路径。在草图的文件夹中,创建一个 data
文件夹,并将您的图像放入其中。
这是一个名为“hexa.png”的图像文件的示例:
您的代码需要 3 张图片,flower0.jpg
、flower1.jpg
和 flower2.jpg
。如果您像我刚刚展示的那样设置草图,那么一切应该会顺利进行(假设草图的其余部分都处于工作状态)。
玩得开心!
,原来文件扩展名隐藏在 win10 中,所以我不断添加 .jpg 两次
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。