如何从字符串图像中获取像素 RGB 值? .get 不适用于 imageLoader(处理中)

How to get pixel RGB values from string images? .get doesn't work with imageLoader (Processing)

我试图从每 2 秒从文件夹中随机选择的图像中获取像素值。例如,我可以轻松地从 PImage 获取像素亮度。但是当我有文件夹中的字符串图像时不知道如何获取。

我也尝试过图像数组,但仍然无法弄清楚如何获取像素 RGB 值

String path = sketchPath("data");
ImageLoader loader;
ImageList list;
Image img;
PImage terrain;
+other data

void setup(){
  loader = new FileImageLoader(this);
  list = loader.start(path);
  img = list.getRandom();
+other data

  void update1(){
      if (img == null) {
    img = list.getRandom();
(error line)    terrain = loadImage(img, "jpg");
    color c = terrain.get(int(p.x), int(p.y));
+other data

我已经预料到该行会出现错误,但为了说明我正在尝试做什么,我将其放在这里。 以及我面临的错误:"The method loadImage(String, String) in the type PApplet is not applicable for the arguments (Image, String)"

是否有任何其他方法可以从通过字符串调用的图像中获取像素数据?或者如何解决这个问题?

方法 Image.getImg() gives you access to the PImage,由 Image 对象管理。

使用.get() and .set()访问图像的像素。

Image img;
PImage terrain;

void update1() {

    if (img == null) {

        img = list.getRandom();
        terrain = image.getImg(); // get PImage from Image
        color c = terrain.get(int(p.x), int(p.y)); 

        // [...]
    }
}