PGraphics color and saving

Had a go at this.

Apparently, P2D or any of the other documented renderers for createGraphics doesn’t work? (P2D, P3D, SVG and maybe PDF. I couldn’t test PDF because of some other error I didn’t resolve atm). Tried FX2D but that didn’t work either.

But if you don’t specify one, it works. I don’t know what renderer it uses then.

Also, use colorMode after beginDraw.

private PGraphics pg;

public void settings() {
  size(400, 400, P2D);
}

public void setup() {
  colorMode(HSB, 360, 100, 100, 1.0f);
}

public void draw() {
  pg = createGraphics(200, 200);
  //pg.hint(PConstants.DISABLE_ASYNC_SAVEFRAME);
  pg.smooth(8);

  pg.beginDraw();
  pg.colorMode(HSB, 360, 100, 100, 1.0f);

  pg.fill(0, 100, 100);
  pg.rect(0, 0, pg.width-1, pg.height-1);
  pg.endDraw();

  // this works
  image(pg, 0, 0); 

  // this doesn't work (saves completely black image)
  pg.save("foo.png"); 

  // this doesn't work either
  //PImage pi = pg.get();
  //pi.save("foo.png"); 

  noLoop();
}
1 Like