0

我制作了一种将 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值,将所有内容放在一个调用它的方法中......什么都没有。

该程序适用于小图像。关于如何解决它的任何想法?

4

2 回答 2

1

你确定无限循环不是来自change函数吗?您没有向我们提供其实施。

我的建议:

  1. 使用image(toSave, 0, 0)而不是background()
  2. 使用save(fileName)而不是saveFrame()
于 2013-10-21T09:12:42.693 回答
0

您已经noLoop输入void setup,这会阻止在第void draw1 帧之后继续。所以frameRate将完全没有效果..

于 2013-10-12T17:41:59.093 回答