Out of memory when loading images at runtime.
in
Core Library Questions
•
11 months ago
Hi,
I have a very simple sketch.
De webcam saves an image every second and the images are numbers from 0 to x. Then in draw() I load one of those images and display it. The result is a timelaps video that always updates.
Great! Unfortunately it runs out of memory rather quickly.
My question, is there any way I can create an Image and reload it's content from draw() ?
Here's my code:
-----------------------------
import processing.video.*;
Capture myCapture;
String[] cameras = Capture.list();
int frame=1;
int maxFrames=100;
int savedFrame=0;
int delay=0;
PImage displayImage;
int playbackDelay=0;
void setup()
{
frameRate(30);
size(320, 240);
myCapture = new Capture(this, 320, 240, 30);
myCapture.start();
//myCapture.stop();
}
void captureEvent(Capture myCapture) {
myCapture.read();
}
void draw() {
// background(0,0,0);
if (delay>30){
image(myCapture, 0, 0, 320, 240);
savedFrame++;
if (savedFrame>maxFrames){
savedFrame=0;
}
save("currentFrame"+savedFrame+".png");
delay=0;
}
delay++;
frame++;
if (frame>maxFrames){
frame=0;
}
// Load one of the saved images and display it every x frames for timelaps effect.
playbackDelay++;
if (playbackDelay>3){
displayImage = loadImage("currentFrame"+frame+".png");
image(displayImage, 0, 0, 320, 240);
playbackDelay=0;
}
}
1