Simple image viewer
in
Share your Work
•
2 months ago
Here is an example of simple image viewer I have made from the info and examples on this forum.
Feel free to make it complicated. regards, Algwat.
- // sweep image viewer
- File[] list; // Files, not Strings
- //
- PImage[] imgs ; // fn matched images
- int Nimg = 0;
- int sframes = 0;
- int eframes = 0;
- int nframes = 0;
- int lprate = 15 ;
- //String fnmatch = "20130812_18" ; // files matched to this string
- String fnmatch = "20121012_" ; // files matched to this string
- String fpath = "C:\\Users\\alan\\Documents\\Processing\\StereoRotator1\\data\\HI1B" ;
- //String fpath = "F:\\Documents\\DMKALLSKY1\\data\\20130812meteor" ; // filepath to images
- void setup() {
- size(968, 720);
- frameRate(lprate);
- //
- File dir = new File(dataPath(fpath));
- list = dir.listFiles();
- //
- mloop() ; // match file names
- //
- ldloop(); // load matched files
- //
- }
- void draw() {
- background(0);
- floop(); // show image loop
- text("[ "+frameCount+" / "+nframes+" ][ FPS "+lprate+" ]", 500, 10 );
- frameRate(lprate);
- // g.removeCache(imgs); // do not remove this line
- }
- void floop() {
- image(imgs[abs(frameCount)], 0, 0, width, height);
- if (frameCount >= nframes-1) {
- frameCount = -(nframes) ;
- }
- if (frameCount == -1) {
- frameCount = 1 ;
- }
- }
- void mloop() {
- for ( Nimg = 0; Nimg < list.length ; Nimg++) {
- //
- String fn = list[Nimg].getAbsolutePath();
- String[] m2 = match(fn, fnmatch );
- if (m2 != null) {
- eframes = Nimg ;
- nframes++ ;
- // println(list.length+" "+sframes+" "+eframes+" "+nframes+ "Match found in '" + list[Nimg] + "'\n"+fn);
- }
- else {
- // This will print to the console, since no match was found.
- sframes = (eframes - nframes) ;
- // println(sframes+" "+eframes+" "+nframes+ "No match found in '" + list[Nimg] + "'\n"+fn);
- }
- }
- }
- void ldloop() {
- // load matched images
- imgs = new PImage[nframes];
- for (int x = 1; x < nframes; x++)
- {
- imgs[x] = loadImage(list[(sframes+x)].getAbsolutePath());
- print( x + " images loaded\n ") ;
- }
- }
- void keyPressed() {
- //
- if (key =='x') {
- exit();
- }
- if (key =='c') {
- background(0);
- }
- if (key =='-') {
- lprate=lprate-1 ;
- if (lprate <= 0) {
- lprate=1 ;
- }
- }
- if (key =='=') {
- lprate=lprate+1 ;
- if (lprate >= 30) {
- lprate= 30 ;
- }
- }
- //
- }