MCPcopy Index your code
hub / github.com/benfry/processing4 / resizeImage

Method resizeImage

core/src/processing/awt/ShimAWT.java:240–268  ·  view source on GitHub ↗
(PImage img, int w, int h)

Source from the content-addressed store, hash-verified

238
239
240 static public void resizeImage(PImage img, int w, int h) { // ignore
241 if (w <= 0 && h <= 0) {
242 throw new IllegalArgumentException("width or height must be > 0 for resize");
243 }
244
245 if (w == 0) { // Use height to determine relative size
246 float diff = (float) h / (float) img.height;
247 w = (int) (img.width * diff);
248 } else if (h == 0) { // Use the width to determine relative size
249 float diff = (float) w / (float) img.width;
250 h = (int) (img.height * diff);
251 }
252
253 BufferedImage bimg =
254 shrinkImage((BufferedImage) img.getNative(), w*img.pixelDensity, h*img.pixelDensity);
255
256 PImage temp = new PImageAWT(bimg);
257 img.pixelWidth = temp.width;
258 img.pixelHeight = temp.height;
259
260 // Get the resized pixel array
261 img.pixels = temp.pixels;
262
263 img.width = img.pixelWidth / img.pixelDensity;
264 img.height = img.pixelHeight / img.pixelDensity;
265
266 // Mark the pixels array as altered
267 img.updatePixels();
268 }
269
270
271 // Adapted from getFasterScaledInstance() method from page 111 of

Callers 1

resizeMethod · 0.95

Calls 3

shrinkImageMethod · 0.95
getNativeMethod · 0.65
updatePixelsMethod · 0.45

Tested by

no test coverage detected