( begin auto-generated from PImage_resize.xml ) Resize the image to a new width and height. To make the image scale proportionally, use 0 as the value for the wide or high parameter. For instance, to make the width of an image 150 pixels, and change the height using the same proportio
(int w, int h)
| 547 | * @see PImage#get(int, int, int, int) |
| 548 | */ |
| 549 | public void resize(int w, int h) { // ignore |
| 550 | if (w <= 0 && h <= 0) { |
| 551 | throw new IllegalArgumentException("width or height must be > 0 for resize"); |
| 552 | } |
| 553 | |
| 554 | if (w == 0) { // Use height to determine relative size |
| 555 | float diff = (float) h / (float) height; |
| 556 | w = (int) (width * diff); |
| 557 | } else if (h == 0) { // Use the width to determine relative size |
| 558 | float diff = (float) w / (float) width; |
| 559 | h = (int) (height * diff); |
| 560 | } |
| 561 | |
| 562 | BufferedImage img = |
| 563 | shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity); |
| 564 | |
| 565 | PImage temp = new PImage(img); |
| 566 | this.pixelWidth = temp.width; |
| 567 | this.pixelHeight = temp.height; |
| 568 | |
| 569 | // Get the resized pixel array |
| 570 | this.pixels = temp.pixels; |
| 571 | |
| 572 | this.width = pixelWidth / pixelDensity; |
| 573 | this.height = pixelHeight / pixelDensity; |
| 574 | |
| 575 | // Mark the pixels array as altered |
| 576 | updatePixels(); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | // Adapted from getFasterScaledInstance() method from page 111 of |
nothing calls this directly
no test coverage detected