The get() function returns the wrong image size

When using get() to grab the screen, the image grabbed is always half the dimensions of the dimensions requested. Here the image being loaded is 512x512 to fit the canvas but after grabbing using new logo = get(0, 0, 512, 512) , it only gets 256x256 image?

MacBook Air, Processing 4.4.4

PImage logo, newlogo ;

void setup() {
  size(512,512) ;
  logo = loadImage(“data/myLogo_512.png”);
}

void draw() {
  background(0) ;
  if(newlogo != null) {
    image(newlogo, 0, 0);
  }
  else {
    image(logo, 0, 0, 512, 512);
  }
}

void mouseReleased() {
  newlogo = get(0, 0, 512, 512);
  newlogo.save(“data/newlogo.png”);
}

Two things to try but not at the same time!

  1. add pixelDensity(1); in setup after size, or
  2. change image(logo, 0, 0, 512, 512); to `image(logo, 0, 0, 1024, 1024);

I suspect that the first should work but the second is speculative. :smile:

1 Like

Hello @shedMusic ,

See issue here:

:)

1 Like

yes using pixelDensity(109 works (but not your other possible solution)

Many thanks :slight_smile:

Many thanks for the info. Not sure it’s actually a bug from reading that, but if I can just set the pixelDensity to get round out, then that’s fine :+1:

Just had another thought - instead of changing the pixel density try changing
image(newlogo, 0, 0); to image(newlogo, 0, 0, 512, 512);

It is not a bug. Before hires monitors a pixel in a bitmap matched a pixel on the screen i.e. a pixel density of 1.

You are using a MacBook Air most probably with a retina display which has a pixel density of 2 so a screen pixel is a 2x2 pixel square in the bitmap image so when displayed the image appears to be half the size.

By specifying both the position, width and height you are telling Processing the actual display position and size to use. This gives a consistent output no matter what your pixel density.

1 Like

Yes I tried that already … the new image becomes 1024x1024 :exploding_head:

Just setting the pixel density fixes this for me :+1:

I changed the subject to make it lower case for get() since it forced uppercase for the G as the first letter.

Wonder if there was a better way.

Hope you don’t mind.

:)

I don’t mind :grinning_face_with_smiling_eyes:

I did notice that … and should have changed it!

1 Like