Reputation: 1025
I made a method that saves a PImage
into a file (.png
, .jpg
, etc...), but if the file exceeds a certain size [not size on disk, I mean the dimensions], the program will repeat over and over again.
I post the method and a lighter version of the sketch.
Sketch:
void setup(){
noLoop();
size(300, 300);
}
void draw(){
background(0);
text("Hello world!", 15, 15);
PImage toEdit = loadImage("C:\\Users\\ingrossod\\Desktop\\toEdit.png");
PImage toSave = change(toEdit, color(86, 177, 222), color(239, 254, 255));
save(toSave, "C:\\Users\\ingrossod\\Desktop\\edited"); // The file extension is missing
}
Now, PImage change(PImage, color, color)
takes a PImage
and substitutes a color with another.
Here is void save(PImage, String)
:
void save(PImage toSave, String fileName){
fileName += ".png"; // Adding the extension
// Saving the current frame
int oldWidth = width;
int oldHeight = height;
saveFrame(fileName);
PImage oldFrame = loadImage(fileName);
// Modifyng the current frame with the image I want to save
size(toSave.width, toSave.height);
background(toSave);
saveFrame(fileName);
// Restoring the frame with old parameters
size(oldWidth, oldHeight);
background(oldFrame);
}
I already tried modifying frameRate
value, putting everything in one method calling it...
Nothing.
The program WORKS with small images. Any idea on how to solve it?
Upvotes: 0
Views: 298
Reputation: 1082
Are you sure that infinite loop is not from change
function? You do not provide us with its implementation.
My advice:
image(toSave, 0, 0)
instead of background()
save(fileName)
instead of saveFrame()
Upvotes: 1
Reputation: 23680
You've put noLoop
in void setup
, which prevents void draw
continuing after frame 1. So frameRate
is going to have precisely no effect..
Upvotes: 0