PGraphics color and saving

I know that some stuff like pg.fill(); works outside, but it seems colorMode doesn’t.

-> put it in between beginDraw() and endDraw(). works for me.

PGraphics pg;
public void settings() {
  size(400, 400, P2D);
}
public void setup() {
  pg = createGraphics(200, 200, P2D);
  pg.beginDraw();
  pg.colorMode(HSB, 100, 100, 100, 255);
  pg.endDraw();        
  colorMode(HSB, 100, 100, 100, 255);
}

public void draw() {
  pg.beginDraw();
  pg.fill(0, 100, 100);
  pg.rect(0, 0, pg.width, pg.height);
  pg.endDraw();
  // this works
  image(pg, 0, 0);        
  // this doesn't work (saves completely black image)
  pg.save("redimage.png"); 
  noLoop();
}
1 Like