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

Alperen Sahin :

I'm trying to get pixel values from images selected randomly from a folder with every 2 seconds. For example i can get pixel brightness from a PImage easily. but don't know how to get when I have String images from a folder.

I have also tried array of images but still couldn't figure out how to get pixel RGB values

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

I was already expecting the error in that line but to give the idea what I am trying to do I put it here. and the error I'm facing: "The method loadImage(String, String) in the type PApplet is not applicable for the arguments (Image, String)"

Are there any other ways to get pixel data from images called via string? Or how to fix this problem?

Rabbid76 :

The method Image.getImg() gives you access to the PImage, which is manged by the Image object.

Use .get() and .set() to access the pixels of the image.

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)); 

        // [...]
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=163362&siteId=1