fix class cast by pulling image data separately (resolves #624)

This commit is contained in:
Ben Fry
2023-01-10 22:17:59 -05:00
parent 532c68ead5
commit 683a86563d
2 changed files with 17 additions and 1 deletions
+13 -1
View File
@@ -3007,7 +3007,19 @@ public class PGraphicsJava2D extends PGraphics {
public void copy(PImage src,
int sx, int sy, int sw, int sh,
int dx, int dy, int dw, int dh) {
g2.drawImage((Image) src.getNative(),
Image nativeImage;
if (src instanceof PGraphicsJava2D) {
// if it's a Java2D drawing surface, use its backing image
nativeImage = ((PGraphicsJava2D) src).image;
} else if (src.getNative() instanceof Image) { // may be null
// if it's something else that has a java.awt.Image as its native backing
nativeImage = (Image) src.getNative();
} else {
// much slower: grab the pixels with get() and create a native image
nativeImage = (Image) src.get(sx, sy, sw, sh).getNative();
}
g2.drawImage(nativeImage,
dx, dy, dx + dw, dy + dh,
sx, sy, sx + sw, sy + sh, null);
}
+4
View File
@@ -1,4 +1,8 @@
1290 (4.1.2?)
X Fix ClassCastException with copy() and PGraphicsJava2D
X https://github.com/processing/processing4/issues/624
_ show an error when calling clear() on the main drawing surface
_ https://github.com/processing/processing4/issues/627