We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi all,
Happy new year.
Here's a problem i'm labouring over these last few days.
I want to load folders of images into an array of Pimages.
requirements: separate folders with the datapath. number of images will vary and will not be sequentially named (if possible).
so i guessed i'd need an arraylist and append the images into it.
This is how far i got. Clearly i'm muddling my arrays, strings etc.
java.io.File folder = new java.io.File(dataPath(""));
// this is the filter (returns true if file's extension is .jpg)
java.io.FilenameFilter jpgFilter = new java.io.FilenameFilter() {
boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jpg");
}
};
// list the files in the data folder
String[] filenames = folder.list(jpgFilter);
// get the number of jpg files
println(filenames.length + " jpg files in specified directory");
PImage [] imgAsset = new PImage [filenames.length];
for (int i = 0; i < filenames.length; i++) {
imgAsset[i] = loadImage(filenames[i]);
}
image(imgAsset[5], 0, 0);
//the 5 in the above is to test the array. it will be a variable in the final code.
Answers
https://forum.Processing.org/two/discussion/17111/how-to-display-a-random-image-using-processing#Item_3
yeah i did see that. Couldn't figure out the Pimage call.
https://Processing.org/reference/loadImage_.html
thanks again @gotoloop. I enjoyed your verbose responses!
TIL - how to use strings as url.
final code:
Well, URL are strings w/ things like
http://
on it. :-\"Although I don't get what URLs got anything to do w/ FilenameFilter and dataFile(). 8-|
ok, so how do i have separate folders of images that all add into the main arraylist? i figure i loop through the code appending each time, but it's getting very muddled.