0
votes

I'm trying to load the image in a separate class and draw it in the main draw function. I get such an error:

The method image(PImage, float, float) in the type PApplet is not applicable for the arguments (main.image, int, int)

Here is the Image class code:

class Image{

PImage img;

Image(){ 
img = new PImage(); 
img = loadImage("test.jpg"); }

}

And here is the main file:

Image img;

void setup(){ 
img = new Image(this); 
}

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

Can anyone help please?

1

1 Answers

0
votes

The error says it all: Processing doesn't know how to draw your Image class. It doesn't magically know to use the PImage img from your Image class. You have to specifically tell it to use the PImage:

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

Your naming scheme makes that look a little awkward, but you're referring to the PImage image of your Image named img and telling Processing to draw that instead.

You might want to use a getPImage() function instead of referring to the variable directly. Also note that you're passing the PApplet into the Image constructor using the this keyword, but your Image constructor does not take any arguments.