This is my conde and works ok, its probably that this code looks dirty, but it allows me use paths and files from my disk susccesfully, move through a text file line per line using the keyboard, name files,create paths etc, i hope someone finds it helpful.
PImage img,img2;
int j=0;
int y=0,z=0;
String[] datos;
String Pathdatos,Pathfotos;
String[] dat;
String foto,carpeta,hv;
PImage existe;
float escala;
void setup() {
img = loadImage("NUEVO FORMATO HV COMFABOY 2013_Page_1.jpg");
img2 = null;
size(img.width,img.height);
fill(0);
selectInput("Seleccione fuente de datos:", "fileSelected");
selectFolder("SELECCIONE LA CARPETA QUE CONTIENE LAS CARPETAS CON FOTOS:", "folderSelected");
}
void draw() {
// Displays the image at its actual size at point (0,0)
image(img,0,0,img.width,img.height);
if (img2 != null){
image(img2,0,230,int(img.width*escala),int(img.width*escala));
}
if(y!=0){
mostrardatos();
}
/*int x = mouseX;
int y = mouseY;
text(x,mouseX+10,mouseY);
text(y,mouseX+40,mouseY);*/ //to see x and y mouse pos.
}
void keyPressed() {
char bs = 92;
if (key == 'A'||key == 'a') {
img2=null;
if(j+1<(datos.length)){
j++;
dat = split(datos[j],TAB);
foto = dat[9]+".jpg";
carpeta = Pathfotos+ bs + dat[1] + bs + foto;
hv = Pathfotos+ bs + dat[1] + bs + "hojas de vida" + bs;
println(carpeta);
println(hv);
z=0;
}
}
if (key == 'S'||key == 's') {
img2=null;
if(j-1>=0){
j--;
dat = split(datos[j],TAB);
foto = dat[9]+".jpg";
carpeta = Pathfotos+ bs + dat[1] + bs + foto;
println(carpeta);
z=0;
}
}
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
exit();
} else {
println("User selected " + selection.getAbsolutePath());
Pathdatos = selection.getAbsolutePath();
datos = loadStrings(Pathdatos);
dat = split(datos[j],TAB);
y=1;
}
}
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
exit();
} else {
println("User selected " + selection.getAbsolutePath());
Pathfotos = selection.getAbsolutePath();
}
}
void mostrardatos(){
if(z==0){
try {
existe = loadImage(carpeta);
} catch ( Exception e ) {
existe = null;
}
if (existe == null) {
println("no existe foto"); // This line is printed
z=1;
} else {
//println(foto);
img2=(loadImage(carpeta));
escala=(400.0/img2.width);
}
}
text(dat[2],135,190);
text(dat[3],381,190);
text(dat[4],818,190);
String nombre = dat[0]+".jpg";
save(hv+nombre);
}
Comments
This is my conde and works ok, its probably that this code looks dirty, but it allows me use paths and files from my disk susccesfully, move through a text file line per line using the keyboard, name files,create paths etc, i hope someone finds it helpful.