We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Image Issues (Read 1393 times)
Image Issues
May 27th, 2010, 8:18am
 
Hi,

I have an issue with images.

I have an image declared at the top of my code

PImage pic_a;

Then in void setup() I have the path of the image declared:

 pic_a= loadImage("a.png");

There are several different images declared in this way....

Then in XML I am using for loops to find out which image I want to display depending on the XML child data using getName().

I want to put that get name (which I guarantee is the same as the image variable I've declared above) in to the image function:

image(xml_child.getName(),xord,yord,32,32);

However when I do this I get the error:

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

What does this mean and is there a way to fix it???

Thanks,
IceKat.
Re: Image Issues
Reply #1 - May 27th, 2010, 8:53am
 
getName() will return a string, the name of the image, while image() expects to get a PImage. Different stuff.
If you use each image only once and your sketch isn't time critical, you can do the loadImage using this string on the fly then use image(loadedImage, ...) there.

Otherwise, more efficiently, you need to find back a PImage depending on the name of the file. For this, you can use a HashMap. Use the image name as key to put the PImage objects, use the getName() as key to get them back.
Re: Image Issues
Reply #2 - May 27th, 2010, 8:30pm
 
Ok. So I can't do it the way I want.

Here's the problem.

I have an XML file which is using children to tell me which image to display. The image path/PImage variable is exactly the same as the filename.

I need to get the XML child and then find out which image it is (in other words compare it to the PImage variable and then if it matches then print it.

What are my options??

I tried :

if(images[b].equals(tiles.getName())){
}

but it always winds up false.....of course...because "images[b]" is a PImage variable array. I know they are the same but the computer doesn't.

Can I turn the "images[b]" variable in to a string just for the checking purposes??
Re: Image Issues
Reply #3 - May 27th, 2010, 11:03pm
 
the same problem as before, PImage is not a String.
So like PhiLho suggested. You can use a HashMap. Instead of using an index to access your images you use a given string, in your case the information you get from the xml file.

Another idea he mentioned is to load the image when needed, so in this case you have one PImage.
in this case  pic_a= loadImage("tiles.getName()"); and just overwrite it when you need another image.
Page Index Toggle Pages: 1