Processing 4 resize()

Hi, I’m trying to use resize() in Processing 4:

masque.resize(img.width, img.height);

But I’ve got this error : RuntimeException: resize() not implemented for this PImage type

It’s work fine with 3.5.4, there is a way to go around or it’s planned to implement ?

1 Like

Hi,

If you look into the processing 4 GitHub repo, you can find the source file where it throws an error :

~/Downloads/processing4   master  grep -n -R "PImage type"
core/src/processing/core/PImage.java:492:    throw new RuntimeException("resize() not implemented for this PImage type");

Which leads to :

/**
   *
   * Resize the image to a new width and height. To make the image scale
   * proportionally, use 0 as the value for the <b>wide</b> or <b>high</b>
   * parameter. For instance, to make the width of an image 150 pixels, and
   * change the height using the same proportion, use resize(150, 0).<br />
   * <br />
   * Even though a PGraphics is technically a PImage, it is not possible to
   * rescale the image data found in a PGraphics. (It's simply not possible
   * to do this consistently across renderers: technically infeasible with
   * P3D, or what would it even do with PDF?) If you want to resize PGraphics
   * content, first get a copy of its image data using the <b>get()</b>
   * method, and call <b>resize()</b> on the PImage that is returned.
   *
   * @webref pimage:method
   * @webBrief Resize the image to a new width and height.
   * @usage web_application
   * @param w the resized image width
   * @param h the resized image height
   * @see PImage#get(int, int, int, int)
   */
  public void resize(int w, int h) {  // ignore
    throw new RuntimeException("resize() not implemented for this PImage type");
  }

It explains clearly why you can’t resize PGraphics. But it’s strange because it’s in the PImage source file…

You should open an issue on GitHub maybe it’s a mistake :wink:

2 Likes

This strongly smells like a big regression which attempts to make PImage objects bound to the current renderer like PGraphics already are. :nose:

Such change would make multi-thread sketches even harder to code! :angry:

1 Like

I found a solution :

masque = createImage(img.width, img.height, ALPHA);
masque.copy(masques[m], 0, 0, masques[m].width, masques[m].height,
 0, 0, img.width, img.height);
        
2 Likes