Created
June 23, 2012 13:52
-
-
Save sport4minus/2978360 to your computer and use it in GitHub Desktop.
load image sequence in processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* this code snippet can be used in the processing environment to load all images in a folder | |
* "input" in the sketches' data folder into an array of PImages. | |
* ideally, the images are sequentially named, like 0001.jpg, 0002.jpg etc. | |
* in this demo, te images are sequentially displayed. | |
*/ | |
PImage[] imageSequence; | |
String[] imageFilenames; | |
void setup() { | |
size(800, 600); | |
//Java's File Class is used to navigate the file system | |
File inputDirectory = new File(dataPath("input")); | |
//ignore invisible files (osx, linux) | |
FilenameFilter filter = new FilenameFilter() { | |
public boolean accept(File dir, String name) { | |
return !name.startsWith("."); | |
} | |
}; | |
imageFilenames = inputDirectory.list(filter); | |
imageSequence = new PImage[imageFilenames.length]; | |
for (int i = 0; i < imageFilenames.length; i++) { | |
imageSequence[i] = loadImage("input"+File.separator+imageFilenames[i]); | |
} | |
} | |
void draw() { | |
image(imageSequence[frameCount%imageSequence.length], 0, 0, width, height); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment