Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Animated Gif SlideShow

$
0
0

Hi there, I'm trying to display a dozen of animated Gif. I display them one by one : - I load and display the first Gif - after a certain time, I load and display the second gif, - after a certain time, I load and display the third gif, - etc.

The problem is I reach a OutOfMemory error.

How can I fix my code to avoid this ?

import gifAnimation.*;

Gif loopingGif;
int maxGif;
String dirGif;
int posGif =1;

void setup() {
  maxGif = 85; // I have 85 animated gif to display one by one
  dirGif = "bw/bbg/";
  posGif = 1;
  frameRate(25);
  size(1024, 768);
  imageMode(CENTER);
  background (0);
  loopingGif  = new Gif(this, dirGif+nameGif(posGif)+".gif");
  loopingGif.play();
}

void draw () {
 if (frameCount%200==0) { // every 200 frames (about 4 seconds), I switch to the next gif
   nextImage();
 }
 image(loopingGif, width/2 , height/2);
}

String nameGif(int pos) {
  return nf(pos, 3);
}

void nextImage() {
  if (posGif>maxGif) {
    posGif=0;
  }
  else {
    posGif++;
  }
  loopingGif.dispose();
  loopingGif = null;
  loopingGif  = new Gif(this, dirGif+nameGif(posGif)+".gif"); // The OutOfMemory is here, after 2 gifs loaded
  loopingGif.play();
}

Please, help meeeeeee..

Thanx

Jean


Viewing all articles
Browse latest Browse all 2896

Trending Articles