how to export application with embedded images
in
Integration and Hardware
•
9 months ago
I need to export my processing program as an application. I'm accessing the images from separate folders but I need them to be all in one place in the application. Can this be done? Or do I need to add all the files individually?
A bit messy and repetitive, but here's my code.
PImage[] images1;
PImage[] images2;
PImage[] images3;
PImage[] images4;
String[] imageNames;
int imageCount = 0;
int ilength;
void setup() {
size(1376, 1008);
imageMode(CENTER);
background(255);
frameRate(1);
File dir1 = new File(sketchPath, "/face1");
if (dir1.isDirectory()) {
String[] contents = dir1.list();
ilength = contents.length;
images1 = new PImage[contents.length];
imageNames = new String[contents.length];
for (int i = 0 ; i < contents.length; i++) {
// skip hidden files and folders starting with a dot, load .png files only
if (contents[i].charAt(0) == '.') continue;
else if (contents[i].toLowerCase().endsWith(".jpg")) {
File childFile = new File(dir1, contents[i]);
images1[imageCount] = loadImage(childFile.getPath());
imageNames[imageCount] = childFile.getName();
println(imageCount+" "+contents[i]+" "+childFile.getPath());
imageCount++;
}
}
}
imageCount = 0;
File dir2 = new File(sketchPath, "/face2");
if (dir2.isDirectory()) {
String[] contents = dir2.list();
println(dir2.list());
ilength = contents.length;
println("Length2: " + contents.length);
images2 = new PImage[contents.length];
imageNames = new String[contents.length];
for (int i = 0 ; i < contents.length; i++) {
// skip hidden files and folders starting with a dot, load .png files only
if (contents[i].charAt(0) == '.') continue;
else if (contents[i].toLowerCase().endsWith(".jpg")) {
File childFile = new File(dir2, contents[i]);
images2[imageCount] = loadImage(childFile.getPath());
imageNames[imageCount] = childFile.getName();
println(imageCount+" "+contents[i]+" "+childFile.getPath());
imageCount++;
}
}
}
imageCount = 0;
File dir3 = new File(sketchPath, "/face3");
if (dir3.isDirectory()) {
String[] contents = dir3.list();
println(dir3.list());
ilength = contents.length;
images3 = new PImage[contents.length];
imageNames = new String[contents.length];
for (int i = 0 ; i < contents.length; i++) {
// skip hidden files and folders starting with a dot, load .png files only
if (contents[i].charAt(0) == '.') continue;
else if (contents[i].toLowerCase().endsWith(".jpg")) {
File childFile = new File(dir3, contents[i]);
images3[imageCount] = loadImage(childFile.getPath());
imageNames[imageCount] = childFile.getName();
println(imageCount+" "+contents[i]+" "+childFile.getPath());
imageCount++;
}
}
}
imageCount = 0;
File dir4 = new File(sketchPath, "/face4");
if (dir4.isDirectory()) {
String[] contents = dir4.list();
ilength = contents.length;
images4 = new PImage[contents.length];
imageNames = new String[contents.length];
for (int i = 0 ; i < contents.length; i++) {
// skip hidden files and folders starting with a dot, load .png files only
if (contents[i].charAt(0) == '.') continue;
else if (contents[i].toLowerCase().endsWith(".jpg")) {
File childFile = new File(dir4, contents[i]);
images4[imageCount] = loadImage(childFile.getPath());
imageNames[imageCount] = childFile.getName();
println(imageCount+" "+contents[i]+" "+childFile.getPath());
imageCount++;
}
}
}
}
void draw() {
//setting random values for images
int randindex1=int(random (0, images1.length));
int randindex2=int(random (0, images2.length));
int randindex3=int(random (0, images3.length));
int randindex4=int(random (0, images4.length));
int randindex5=int(random (0, images1.length));
int randindex6=int(random (0, images2.length));
int randindex7=int(random (0, images3.length));
int randindex8=int(random (0, images4.length));
imageMode(CORNER);
//displaying the images
image(images1[randindex1], 0, 0);
image(images2[randindex2], 344, 0);
image(images3[randindex3], 0, 504);
image(images4[randindex4], 344, 504);
image(images1[randindex5], 688, 0);
image(images2[randindex6], 1032, 0);
image(images3[randindex7], 688, 504);
image(images4[randindex8], 1032, 504);
}
1