在 class 中使用 Piamge 处理 (java)

Processing (java) using Piamge in a class

我需要在 class 中使用 piamge。

class ball {

  String shape;
  int number;
  color col;
  PImage ballimg;

  ball(String s, int n, color c, ?) {
    shape = s;
    number = n;
    col = c;
    ballimg = loadImage("?") // i need this in the parameters of ball to give it to the class
  }
  }

我需要在函数 ball() 的参数中给出图像,需要在 ? 上做什么?

希望有人能帮我解决这个问题

“?”参数是文件名。

从这个documentation / tutorial:

PImage img;

void setup() {
  // Images must be in the "data" directory to load correctly
  img = loadImage("myImage.jpg");
}

void draw() {
  image(img, 0, 0);
}

图像必须位于草图的 "data" 目录中才能正确加载。 Select "Add file..." 从 "Sketch" 菜单将图像添加到数据目录,或者直接将图像文件拖到草图上 window。 Processing 当前适用于 GIF、JPEG 和 PNG 图像。

您可以在这样的对象中使用它:

PImage ball_img;


void setup() {
  ball_img = loadImage("myImage.jpg");


  ball_a = new Ball(ball_img);
}


class Ball {

  PImage ballimg;

  ball(PImage img) {
    ballimg = img;
  }
}