Surface Resize issues

Hi, I am having trouble changing the size of my surface in a sketch.

Basically I load an image, set the surface size to the size of the image then draw circles on the surface.

The issue is that Processing is actually scaling the surface after I draw the circles instead of before so if my image is 1000x1000 pixels and I start with a size of 100,100, everything gets scales 10x.

I would like to resize the surface prior to drawing the circles.

It seems like the resize doesn’t happen until the end of draw().

Is there any way round this?

Thanks

Phil

size(100,100);
img = loadImage(path);   
      int sx = img.width;
      int sy = img.height;
      surface.setResizable(true);
      surface.setSize(sx, sy);

      // now I add all my circles

maybe this helps?

scale(0.1);

Hey I think you just have to re draw you circles :slight_smile:

Here is the code I wrote:

PImage img;

boolean keyWasPressed = false;

void setup() {
  size(600, 600);
  frameRate(1);
  //load the image on start so the programm dont have to load it while running.. 
  img = loadImage("https://pixy.org/src/480/4800346.jpg");
}
void draw() {
  background(0);
  fill(255);
  textAlign(CENTER, CENTER);
  textSize(60);
  text("PRESS A KEY", 0, 0, width, height);

  fill(255);
  ellipse(200, 200, 30, 30);

  if (keyWasPressed) {
    //if key was pressed draw the image with alpha = 120
    tint(255, 120);
    image(img, 0, 0);
  }
}
void keyPressed() {
  keyWasPressed = true;
  surface.setSize(img.width, img.height);
}
1 Like