我制作了一种将 a 保存PImage
到文件中的方法(.png
,.jpg
等...),但是如果文件超过一定大小[不是磁盘上的大小,我的意思是尺寸],程序将一遍又一遍地重复。
我发布了草图的方法和更轻的版本。
草图:
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
}
现在,PImage change(PImage, color, color)
用PImage
另一种颜色替换一种颜色。
这里是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);
}
我已经尝试过修改frameRate
值,将所有内容放在一个调用它的方法中......什么都没有。
该程序适用于小图像。关于如何解决它的任何想法?