2

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
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

0

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

        // [...]
    }
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • thanks, now i have this: `void update1(){ if (img == null) { img = list.getRandom(); terrain = img.getImg(); color c = terrain.get(int(p.x), int(p.y)); float t = (brightness(c) / 200.0);` now i don't have any error but the when i run the code it's just grey screen i couldn't understand what I need to do with `.set()` are there any explanations about all functions for `Image` class online? – Alperen Sahin May 22 '19 at 22:30
  • i figured it out... i needed to call the images in `setup` not in `void`. so problem was my clumsiness in coding. thanks again for help. – Alperen Sahin May 23 '19 at 00:16