Skip to content

Error when using .get() on PImage and PGraphics layers #1255

@jake-welch-design

Description

@jake-welch-design

Most appropriate sub-area of Processing 4?

Image

Processing version

4.4.7

Operating system

MacOS

Bug description

When using .get() on a PImage or PGraphics layer, only data from the top left quadrant of the layer is retrieved, and it is scaled up. I tested this on an old sketch that used to use a buffer this way and I can confirm that it behaves improperly now.

Steps to reproduce this

  1. Display image in a PGraphics Layer

  2. (optional) Create PImage buffer of PGraphics layer with .get()

  3. Use .get() on either the PGraphics layer or the PImage buffer and display the data. I illustrate this with a pixel grid below.

snippet

PImage img;
PGraphics imgLoad;

void setup() {
  size(1080, 1080);

  imgLoad = createGraphics(width, height);
  img = loadImage("1.jpeg");
  img.resize(width, height);
}


void draw() {
  background(0);

  imgLoad.beginDraw();
  imgLoad.image(img, 0, 0, width, height);
  imgLoad.endDraw();

  PImage imgBuffer = imgLoad.get();

  float tilesX = 150;
  float tilesY = tilesX;
  float tileW = ceil(width / tilesX);
  float tileH = ceil(height / tilesY);

  for (int x = 0; x < tilesX; x++) {
    for (int y = 0; y < tilesY; y++) {

      int px = int(x * tileW);
      int py = int(y * tileH);


      //CHANGE BETWEEN THESE OPTIONS TO SEE THE ISSUE:

      color c = img.get(px, py); // Displays the full image
      //color c = imgLoad.get(px, py); // Displays the top left quadrant of the image
      //color c = imgBuffer.get(px, py); // Displays the top left quadrant of the image


      push();
      stroke(c);
      fill(c);
      rect(px, py, tileW, tileH);
      pop();
    }
  }
}

Additional context

What it should look like:
Image

What it looks like with the bug:
Image

Would you like to work on the issue?

No, I’m just reporting the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions