Surface.setSize() error

Hello,

i’m trying to setSize of my window and discover a strange behaviour.
try this code.

On my MacOS 10.14.6 and Processing 3.5.3

It’s suppose to open a window with 10px in height…
It does not!
it open a window with something like 128px height…

Any idea?

thanks

void setup() {
  surface.setResizable(true);
  surface.setSize(200, 10);
}
1 Like

If setResizable(true) is removed, it works.
it open a 128px window but with a 10px area of display…

void setup() {
  surface.setSize(200, 10);
}

hello, i don’t remember the correct post, but just a short time ago I read that the window cannot be smaller than something about 80 px (or 70, or…) to make it smaller is a bit complicated it seems.

maybe I can dig it up, or you can…
basically these limits set internally override your wish to make it smaller. your code is not wrong imho.

In fact my project was to code a simple image slicer (for a project in js), but i was unable to copy part of image (copy() or get() does not work as expected and did not find a simple example) in a buffer an save the buffer as an image on disk…
therefore i do this, writing in the window, but for sure it is not optimal.

i give it to community as a poor or simple solution (without gui)

PImage img;
int largeur,hauteur,colonnes,tranches;
int compteur = 0;

void setup() {
  tranches = 3;
  colonnes = 3;
  img = loadImage("paysage_grand.jpg");
  largeur = img.width/colonnes;
  hauteur = img.height/tranches;
  surface.setSize(largeur, hauteur);
  surface.setLocation(100, 100);
  frameRate(10);
  //change frameRate if outOfBound on "save line" (too quick for loading image)
}

void draw() {
  image(img,-(compteur/tranches)*largeur,-(compteur%tranches)*hauteur);
  //println((compteur/tranches)*largeur);
  //println((compteur%tranches)*hauteur);
  save("elm_"+compteur+".jpg");
  compteur++;
  if (compteur >= tranches*colonnes) {
    noLoop();
  }
}

regards

é.

1 Like

yes… took me a while to figure it out once, too. you could copy the slice you want into a pGraphics and save that. as usual, you need beginDraw() and endDraw() and tell the code to save the buffer, not the display. (maybe that was the issue with your code.

look at this:

PImage img;
PGraphics one;
//-----------------
void setup() {
  size(400, 600);  
  img = loadImage("woman.png");
  one  = createGraphics(width, height);
}
//-----------------
void draw() {
  one.beginDraw();
  one.copy(img, 100, 50, 100, 100, 100, 50, 100, 100);
  one.endDraw();  
  image(one, 0, 0);    
  one.save("###-image.png");
  noLoop();
}

in your case, you will probably want the Graphics to fit to the size of the slice…
well, there is no rule that would not let you write something to select the image region with your mouse, create the PGraphics on the fly and put your slice in it :slight_smile:

but I did not want to rob you of all the fun developing yourself…

2 Likes

I do not use beginDraw() and endDraw(), that’s why.

thanks for code

is it possible to copy and save in a for…loop in the draw() or do i use the draw with a variable incrementation?

thanks
é.

draw is special -> Adding objects to the canvas fom within the mousePressed() method

you can of course copy several images from within a loop. if you have a method to determine different regions you wanna take from your source image. e.g. you want to copy parts of the image in a grid like manner. making smaller tiles from a larger image… that would either work with incrementing values (like image size and position) or using the loops counter itself.

the classical thing would be (pseudo code):

for i = 0
copy (img, i*50,0, 50,50);

i = 0 -> (img, 0,0,50,50);
i = 1 -> (img, 50,0,50,50);
i = 2 -> (img, 1000,50,50);

so you would copy 50x50 chunks from the left to the right.
if you want to cover the whole image this way, you would have to put a second loop inside the first, so you step through all chunks in the first row, then the second row, then the third…

if your logic does not fit to the regularity of a for loop (maybe you want to select random positions or sizes) you would use some “extra” variable, as you say.

for i = 0
x = random (0,width);
copy (img,x,0, 50,50);
2 Likes