how make image suffix indiffrent

edited December 2013 in How To...

Nonjour When using manny images in a sketch for some sort of "diaporama" with manny images (inside a sketch using KINECT) I am looking for a solution making the image suffixes "indifferent" .............. example:

void setup() {

  size(900,600);
  frameRate(0.5);// speed 1 change the timerate  here between 0.01 and 10
  for(int i=0; i< images.length; i++) {
    images[i] = loadImage("image_" + i + ".jpg");/////for .gif instead of .jpg  change the data folder's images//////
  }  

............ normally you have to put into your DATA folder only images with one and the same suffix -
exemple: image_1.jpg image_2.jpg etc now i want to make use of some image_3.gif image_4.gif etc is there any solution ( a symbole like: * or $....) to make the suffix "indifferent" , in order to accept all the images with all the different suffixes, of coarse inside the suffixes supported by PROCESSING 1.5.1 ........ you see, my english and PROCESSING knowledge are limited , so please be patient

gottfried

Answers

  • it might work if you remove the extension completely, have images called image_0, image_1, image_2 etc and use loadImage("image_" + i);

    i'm thinking that the code will be able to determine the image type without the need for the extension... i haven't tested this though.

  • Perhaps what you want is File.list(dataPath(""))

    Otherwise, if your files are numbered, you can try loadImage() with one extension, and if it returns null, try with another extension... You can wrap this in a function to ease the usage of multiple tries.

    koogs, if no extension is given, I believe the type of image must be given in a second parameter.

  • edited December 2013

    .........yes

    1. it comes with the Null when using different extentions in a DATA file-you have to stick to the same extention of coarse in that specific file
    2. how to put the multiple files in a function to easy there use ?
    3. "no" extention" in a second parameter, why not - where can i find an exemple to go this way?

    but any-how: why not simplify the solution by making the extentions jpg or png or gif just indifferent in former times there would have been the $$$ signs ot *** who replace the extentions....... and i like/need very simplfied solutions yesterday i made in Paris street a big performance-but nobody accepted to 'wait' trgree minutes to let me make the changements of the data folder with the other pictures, so???

    thanks for your kind consideration

  • koog, thanks

    your solution is half-way

    i have this in my sketch i.e. for(int i=0; i< images.length; i++) { images[i] = loadImage("image_" + i + ".png"); but the probleme comes with that extention: ".png" as said to PhiLho

  • running with philho's idea:

    PImage loadImageWithoutExtension(String filename) {
      PImage i = loadImage(filename, "jpg");
      if (i != null) {
        println("jpg");
        return i;
      }
      i = loadImage(filename, "png");
      if (i != null) {
        println("png");
        return i;
      }
      i = loadImage(filename, "gif");
      if (i != null) {
        println("gif");
        return i;
      }
      println("Unknown File Type");
      return null;
    }
    
  • thanks Koogs

    i will try tomorrow, its night now here but this seems very reasonnable

    good night from Paris gottfried

  • edited December 2013

    hello Kogg I made the try with Your first idea "...remove the extension completely, have images called image_0, image_1, image_2 etc and use loadImage("image_" + i);...." ....but I get the Null -the data folder hadn't been changed and is ok with the initial version of the well working sketch

    here is one very simple sketch with 5 images, extention: with only .png for test reasons

    //sketch testing extentions - processing 1.5.1
    
    int compteur = 0;
    PImage[] images = new PImage[5];// 5 or more or less due to your DATA folder
    
    void setup() {
    
      size(900,600);
      frameRate(1);// 1 change the timerate  here
    
      for(int i=0; i< images.length; i++) {
        //images[i] = loadImage("image_" + i + ".png");////former version OK
         images[i] = loadImage("image_" + i);///////gets the Null
      }  
    }
    
    void draw() {
      image( images[compteur], 0, 0);
      compteur++;
      if (compteur >= images.length) compteur = 0;
    }
    
  • philho pointed out that my first idea wouldn't work.

    that later code i posted (december 7) was tested and does work. just put it at the bottom of your code and call that rather than loadImages()

  • yes, I understand now the signe ! makes other, new problems; but I will try harder thanks for today, Koogs

Sign In or Register to comment.