@@ -237,7 +237,7 @@ static public Object getNativeImage(PImage img) {
237
237
}
238
238
239
239
240
- static public void resizeImage (PImage img , int w , int h ) { // ignore
240
+ static public void resizeImage (PImage img , int w , int h , int interpolationMode ) { // ignore
241
241
if (w <= 0 && h <= 0 ) {
242
242
throw new IllegalArgumentException ("width or height must be > 0 for resize" );
243
243
}
@@ -251,7 +251,8 @@ static public void resizeImage(PImage img, int w, int h) { // ignore
251
251
}
252
252
253
253
BufferedImage bimg =
254
- shrinkImage ((BufferedImage ) img .getNative (), w *img .pixelDensity , h *img .pixelDensity );
254
+ shrinkImage ((BufferedImage ) img .getNative (), w *img .pixelDensity ,
255
+ h *img .pixelDensity , interpolationMode );
255
256
256
257
PImage temp = new PImageAWT (bimg );
257
258
img .pixelWidth = temp .width ;
@@ -274,7 +275,8 @@ static public void resizeImage(PImage img, int w, int h) { // ignore
274
275
// plus a fix to deal with an infinite loop if images are expanded.
275
276
// https://github.com/processing/processing/issues/1501
276
277
static private BufferedImage shrinkImage (BufferedImage img ,
277
- int targetWidth , int targetHeight ) {
278
+ int targetWidth , int targetHeight ,
279
+ int interpolationMode ) {
278
280
int type = (img .getTransparency () == Transparency .OPAQUE ) ?
279
281
BufferedImage .TYPE_INT_RGB : BufferedImage .TYPE_INT_ARGB ;
280
282
BufferedImage outgoing = img ;
@@ -313,8 +315,16 @@ static private BufferedImage shrinkImage(BufferedImage img,
313
315
scratchImage = new BufferedImage (w , h , type );
314
316
g2 = scratchImage .createGraphics ();
315
317
}
318
+ // convert the passed int value of interpolationMode to the object expected
319
+ // by setRenderingHint
320
+ Object interpolationModeValue = switch (interpolationMode ) {
321
+ case 0 -> RenderingHints .VALUE_INTERPOLATION_NEAREST_NEIGHBOR ;
322
+ //case 1 is the same as the default
323
+ case 2 -> RenderingHints .VALUE_INTERPOLATION_BICUBIC ;
324
+ default -> RenderingHints .VALUE_INTERPOLATION_BILINEAR ;
325
+ };
316
326
g2 .setRenderingHint (RenderingHints .KEY_INTERPOLATION ,
317
- RenderingHints . VALUE_INTERPOLATION_BILINEAR );
327
+ interpolationModeValue );
318
328
g2 .drawImage (outgoing , 0 , 0 , w , h , 0 , 0 , prevW , prevH , null );
319
329
prevW = w ;
320
330
prevH = h ;
0 commit comments