We are about to switch to a new forum software. Until then we have removed the registration on this forum.
struggling to get my image loader code into a typical Setup/Draw:
import java.io.FilenameFilter;
File folder = dataFile("essentials");
ArrayList<PImage> imgAsset;
final FilenameFilter PIC_FILTER = new FilenameFilter() {
final String[] exts = {
".png", ".jpg", ".jpeg", ".gif"
};
@ Override boolean accept(final File dir, String name) {
name = name.toLowerCase();
for (final String ext : exts) if (name.endsWith(ext)) return true;
return false;
}
};
File[] pics = folder.listFiles(PIC_FILTER);
println("# of files found at folder above:", pics.length, ENTER);
printArray(pics);
println();
void setup() {
size(1200, 1200);
imageMode(CENTER);
imgAsset = new ArrayList<PImage>();
String[] filenames = new String[pics.length];
for (int i = 0; i < pics.length; filenames[i] = pics[i++].getPath());
//add to arraylist
for (int i = 0; i < pics.length; i++) {
PImage p = loadImage(filenames[i], "jpg");
p.resize(round(random(width/2)), 0);
imgAsset.add(p);
};
};
void draw() {
//place image on stage
for (int i=0; i<30; i++) {
image(imgAsset.get(round(random(pics.length-1))), ceil(random(height)), ceil(random(width)));
}
stop();
}
Answers
https://forum.Processing.org/two/discussion/20063/load-folders-of-pimages-multiple-folders-unknown-numbers-non-sequential-filenames