Loading...
Logo
Processing Forum
As the title says, I would like to resize the display window during the execution.

In my program, every time I click on the window I can choose an image to display and I would like the display size fits every time the size of the image displayed.
Something like this:

Copy code
  1. PImage img;

  2. void setup(){
  3.   pickImage();
  4. }

  5. void draw(){
  6. }

  7. void mousePressed(){
  8.     pickImage();
  9. }

  10. void pickImage(){
  11.   String path=selectInput();
  12.   img=loadImage(path);
  13.   size(img.width,img.height);
  14.   image(img,0,0,width,height);
  15. }
But the display window size change only the first time! Any suggestions?

Replies(5)

Use frame.setResizable + frame.setSize, like this...

Adapted Code
Copy code
  1. PImage img;
  2.  
  3. void setup() {
  4.   String path=selectInput();
  5.   img=loadImage(path);
  6.   size(img.width, img.height);
  7.   frame.setResizable(true);
  8. }
  9.  
  10. void draw() {
  11.   image(img, 0, 0);
  12. }
  13.  
  14. void mousePressed() {
  15.   pickImage();
  16. }
  17.  
  18. void pickImage() {
  19.   String path=selectInput();
  20.   img=loadImage(path);
  21.   frame.setSize(img.width, img.height);
  22. }
Thank you! This is exactly what I was looking for :-)
hey thiezar, maybe the size function can be used only in setup function once in a program. I tried this which changes the image but somehow doesn't changes the window size. try this

PImage img;

void setup(){
  pickImage();
}

void draw(){
 // selectImage();
 if(mousePressed == true){
   pickImage();
 }
}

void pickImage(){
  String path=selectInput();
  img=loadImage(path);
  size(img.width,img.height);
  image(img,0,0,width,height); 
}
try this, use frame.Resizable in setup() and frame.setSize() in calling function after you select the new image. it will do what you desire. Image pixels are not loading sometimes, but if you select the same image twice it will load the desired image...below is the code..cheers
Copy code
  1. PImage img;

  2. void setup(){
  3.   //pickImage();
  4.   String path=selectInput();
  5.   img=loadImage(path);
  6.   size(img.width, img.height);
  7. }

  8. void draw(){
  9.  if(mousePressed == true){
  10.    frame.setResizable(true);
  11.    pickImage();
  12.  }
  13. }

  14. void pickImage(){
  15.   String path=selectInput();
  16.   img=loadImage(path);
  17.   frame.setSize(img.width, img.height);
  18.   //size(img.width,img.height);
  19.   image(img,0,0,width,height); 
  20. }