Processing (处理)PGraphics不';从其他图形复制所有像素时,t更新

Processing (处理)PGraphics不';从其他图形复制所有像素时,t更新,processing,pixels,pgraphics,Processing,Pixels,Pgraphics,我在摄影方面有个小问题。我从我正在从事的大型项目中提取了以下代码: int x=0; int y=0; PGraphics array1; PGraphics array2; void setup() { size(200,200); background(0); array1 = createGraphics(200,200); array2 = createGraphics(200,200); frameRate(10); } void draw() { arr

我在摄影方面有个小问题。我从我正在从事的大型项目中提取了以下代码:

int x=0;
int y=0;

PGraphics array1;
PGraphics array2;

void setup() {
  size(200,200);
  background(0);
  array1 = createGraphics(200,200);
  array2 = createGraphics(200,200);
  frameRate(10);
}

void draw() {
  array1.beginDraw();
  array1.background(0);
  array1.noStroke();
  array1.fill(150);
  array1.ellipse(x,y,20,20);
  array1.endDraw();

  array1.loadPixels();
  array2.loadPixels();

  //presence of two below lines doesn't change anything
  array1.updatePixels();
  array2.updatePixels();

  //not by arrayCopy since I want to add filters in next project
  for(int i=0; i<200*200; i++) {
    array2.pixels[i] = array1.pixels[i];
  }

  //presence of two below lines doesn't change anything
  array1.updatePixels();
  array2.updatePixels();

  //I want to see only the array2 - now it should be the same as array1
//  image(array1, 0,0);
  image(array2, 0,0);

  //presence of two below lines doesn't change anything
  array1.updatePixels();
  array2.updatePixels();

  x++;
  y++;
它打印:

...
-6908266 -6908266
-6908266 -6908266
-6908266 -6908266
-16777216 -16777216
-16777216 -16777216
...
显然,两个数组都包含相同的值。我不知道为什么我看不到更新的阵列2

在这些文档之后,我尝试了将updatePixels方法放置在不同的位置,但这没有帮助

我错过了什么


提前谢谢

您忘记为array2 PGraphic调用beginDraw()和endDraw()。如果您这样做:

array2.beginDraw(); // HERE!!
  for (int i= 0; i<array1.pixels.length; i++) {
    array2.pixels[i] = array1.pixels[i];
  }
  array2.updatePixels();
array2.endDraw(); // and HERE!! :)
array2.beginDraw();//在这里

对于(int i=0;iThanks!我知道这一定是一个简单的东西…工作完美!
array2.beginDraw(); // HERE!!
  for (int i= 0; i<array1.pixels.length; i++) {
    array2.pixels[i] = array1.pixels[i];
  }
  array2.updatePixels();
array2.endDraw(); // and HERE!! :)