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.
IndexProgramming Questions & HelpIntegration › Loading images from different locations
Page Index Toggle Pages: 1
Loading images from different locations (Read 966 times)
Loading images from different locations
Jul 24th, 2006, 2:33pm
 
hi @all

how is it possible to load images with Processings from a different location than the "data" directory?

I'm NOT using the Processing IDE (and the sketchbooks and so on ...).

My projekt structure is like this:
.
./bin
./res
./res/img_01.png
./res/img_01.png
./src
./src/my
./src/my/package
./src/my/package/test.java

How is it possible to load an PImage from the resource "./res/img_01.png" in class my.package.Test?

I really have no idea!? Why there aren't methods like:
* loadImage(InputStream inStream), or
* loadImage(File file), or
* loadImage(URL url)????

This whole processing stuff is really hard for a "normal" Java programmer ...

Thanks
k4simir
Re: Loading images from different locations
Reply #1 - Jul 25th, 2006, 9:39pm
 
try
PImage myImage=loadImage(savePath("res/img_01.png"));
or
PImage myImage=loadImage(savePath("/res/img_01.png"));

or something like that and see how it works. Also, possible simply
PImage myImage=loadImage("res/img_01.png");
or
PImage myImage=loadImage("/res/img_01.png");
might work.
Re: Loading images from different locations
Reply #2 - Jul 25th, 2006, 10:31pm
 
I don't think the root expression "." will work because Processing forces a local view of your data system. Referencing the hard drive letter (C:/etc) always works, other than that you could try navigating out of the data folder:

Code:

String [] dave = {"hallo dave", "you my wife now dave"};
saveStrings("../../dave.txt", dave);


The data folder path used to be in a variable called folder but that seems to have changed - my bet would be to find out where Processing is forcing you to look then compensate for the local view.
Re: Loading images from different locations
Reply #3 - Jul 26th, 2006, 3:14pm
 
in answer to the original question, use loadImage() with the full path name to the file (or create a file object and use getAbsolutePath()). but why bother making it this difficult on yourself? just use the processing ide or call your data folder 'data'.

this stuff is "hard" only because you're making it so. processing is set up to make things straightforward in the context of its intended use, it's not a general purpose java library.
Page Index Toggle Pages: 1