diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 666061ee9..eccd25497 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -840,6 +840,14 @@ public void mask(int[] maskArray) { // ignore */ public void mask(PImage img) { img.loadPixels(); + if (this.pixelWidth != img.pixelWidth || this.pixelHeight != img.pixelHeight) { + if (this.pixelDensity != img.pixelDensity) { + throw new IllegalArgumentException("mask() requires the mask image to have the same pixel size after adjusting for pixelDensity."); + } + else if (this.width != img.width || this.height != img.height) { + throw new IllegalArgumentException("mask() requires the mask image to have the same width and height."); + } + } mask(img.pixels); }