We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, I have this code setup that on the first program you select a folder and then it displays the folder of images. Then when you click on an image it opens a code that you have to run that allows you to edit and save the images. However on my second code, it isn't displaying the image. It will allow you to save it if you know the right key to press but it also doesn't apply any of the filters if anyone has any help.
here is the first code to display the images and launch the second code.
PImage images;
String[] filenames;
PImage[] imgs;
int len;
String pathName;
void setup() {
size(1000, 881);
loadFrames();
}
void draw() {
background(0);
displayImages();
if (mousePressed && (mouseButton == LEFT)) {
enlargeAll();
}
textSize(32);
fill(255);
text("word", 450, 45);
}
void loadFrames() {
selectFolder("Select a folder to process:", "folderSelected");
}
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
java.io.File folder = new java.io.File(selection.getAbsolutePath());
filenames = folder.list(); // list the files in the data folder
len = filenames.length;
imgs = new PImage[len];
pathName= selection.getAbsolutePath() +"\\";
}
}
void displayImages(){
int imageY;
float imageX;
//where the photos are placed
imageX = 8.33;
imageY = 200;
int count = 0;
for(int x = 1; x<=len; x++){
count = x;
String toDisplay = pathName + filenames[x - 1];
//size and display of photos
images = loadImage(toDisplay);
images.resize(190, 0);
image(images, imageX, imageY);
//spacing of photos
imageX=imageX+198.33;
if ((count%5 == 0)) {
imageX = 8.33;
imageY = imageY + 150;
}
}
}
void enlarge(int imageNumber) {
//Sets toDisplay as the photo name
String imageNumbs;
if (imageNumber <10) {
imageNumbs = "0" + imageNumber;
}
else
{
imageNumbs = str(imageNumber);
}
String toDisplay = pathName + imageNumbs + ".jpg";
float lowX, highX;
float lowY, highY;
int imageNum = imageNumber;
//Starting point of photo 1
lowY = 200;
highY = 325;
lowX = 8.33;
highX = 198.33;
//Placement of photos 1-5
if (imageNum <=5) {
lowX = 8.33 + ((imageNum - 1) * 198.33);
highX = 198.33 + ((imageNum - 1) * 198.33);
lowY = 200;
highY = 325;
}
else {
//Placement of photos 6-10
if (imageNum >= 6 && imageNum <= 10) {
imageNum = imageNum - 5;
lowX = 8.33 + ((imageNum - 1) * 198.33);
highX = 198.33 + ((imageNum - 1) * 198.33);
lowY = 350;
highY = 475;
}
else {
//Placement of photos 11-15
if (imageNum >= 11 && imageNum <= 15) {
imageNum = imageNum - 10;
lowX = 8.33 + ((imageNum - 1) * 198.33);
highX = 198.33 + ((imageNum - 1) * 198.33);
lowY = 400;
highY = 625;
}
else {
//Placement of photos 16-20
if (imageNum >= 16 && imageNum <= 20) {
imageNum = imageNum - 15;
lowX = 8.33 + ((imageNum - 1) * 198.33);
highX = 198.33 + ((imageNum - 1) * 198.33);
lowY = 550;
highY = 775;
}
}
}
}
//if mouse is on a photo
if((mouseX >= lowX) && (mouseX <= highX) && (mouseY >= lowY) && (mouseY <= highY)) {
//Enlarges photo to full screen
launch(sketchPath() +"\\" +"pic" + imageNumbs + "\\" + "pic" + imageNumbs + ".pde");
}
}
//Enlarges when mouse is clicked
void enlargeAll() {
enlarge(1);
enlarge(2);
enlarge(3);
enlarge(4);
enlarge(5);
enlarge(6);
enlarge(7);
enlarge(8);
enlarge(9);
enlarge(10);
enlarge(11);
enlarge(12);
enlarge(13);
enlarge(14);
enlarge(15);
enlarge(16);
enlarge(17);
enlarge(18);
enlarge(19);
enlarge(20);
}
and here is the second code which is the one that I am having troubles with
PImage images;
String[] filenames;
int len;
String pathName;
String imageToDisplay;
PImage newImage;
void setup() {
size(1000, 881);
loadFrames();
}
void draw() {
noLoop();
redraw();
background(0);
loadImages();
filters();
saveFilter();
textSize(32);
fill(255);
text("word", 450, 45);
}
void loadFrames() {
selectFolder("Select a folder to process:", "folderSelected");
}
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
java.io.File folder = new java.io.File(selection.getAbsolutePath());
filenames = folder.list(); // list the files in the data folder
len = filenames.length;
pathName= selection.getAbsolutePath() +"\\";
imageToDisplay = pathName + "04.jpg";
//size and display of photos
}
}
void loadImages() {
if (imageToDisplay != null) {
images = loadImage(imageToDisplay);
images.resize(0, 656);
newImage = images.get();
image(images, 8.33, 200);
}
}
void filters() {
bFilter();
tFilter();
tFilter();
pFilter();
dFilter();
noFilter();
}
void bFilter() {
if (keyPressed == true) {
if (key == 'b' || key == 'B') {
if (pathName != null) {
image(newImage, 8.33, 200);
newImage.filter(GRAY);
}
}
}
}
void tFilter() {
if (keyPressed == true) {
if (key == 't' || key == 'T') {
if (pathName != null) {
image(newImage, 8.33, 200);
newImage.filter(THRESHOLD);
}
}
}
}
void iFilter() {
if (keyPressed == true) {
if (key == 'i' || key == 'I') {
if (pathName != null) {
imageToDisplay = pathName + "04.jpg";
//size and display of photos
newImage = images.get();
image(newImage, 8.33, 200);
newImage.filter(INVERT);
}
}
}
}
void pFilter() {
if (keyPressed == true) {
if (key == 'p' || key == 'P') {
if (pathName != null) {
image(newImage, 8.33, 200);
newImage.filter(POSTERIZE, 66);
}
}
}
}
void dFilter() {
if (keyPressed == true) {
if (key == 'd' || key == 'D') {
if (pathName != null) {
image(newImage, 8.33, 200);
newImage.filter(DILATE);
}
}
}
}
void noFilter() {
if (keyPressed) {
if (key == CODED) {
if (keyCode == DELETE) {
image(images, 8.33, 200);
}
}
}
}
void saveFilter() {
if (keyPressed == true) {
if (key == CODED) {
if (keyCode == '=') {
int fileName = len+1;
newImage.save(pathName + fileName +".jpg");
}
//save
}
}
}
Answers
Here is the first program which allows me to choose the folder and open that folder with the image and when clicked it'll open the new program to edit. PImage images; String[] filenames; PImage[] imgs; int len; String pathName;
Here is the second part that allows me to add the filters and save the new images.
Now, the issue that I am having is that I can not get it to automatically update and add the new saved image on the original program