Java ByteBuffer Size rescaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint)

Here you can find the source of rescaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint)

Description

Convenience method that returns a scaled instance of the provided BufferedImage .

License

Open Source License

Parameter

Parameter Description
img the original image to be scaled
targetWidth the desired width of the scaled instance, in pixels
targetHeight the desired height of the scaled instance, in pixels
hint one of the rendering hints that corresponds to java.awt.RenderingHints.KEY_INTERPOLATION (e.g. java.awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR , java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR , java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC )

Return

a scaled version of the original BufferedImage

Declaration

public static BufferedImage rescaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint) 

Method Source Code

//package com.java2s;
/*/* w ww.  ja  va  2s  . c  om*/
 * The Shepherd Project - A Mark-Recapture Framework
 * Copyright (C) 2011 Jason Holmberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import java.awt.Graphics2D;

import java.awt.RenderingHints;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Convenience method that returns a scaled instance of the
     * provided {@code BufferedImage}.
     * Any transparency/alpha of the original image is not preserved.
     *
     * @param img the original image to be scaled
     * @param targetWidth the desired width of the scaled instance, in pixels
     * @param targetHeight the desired height of the scaled instance, in pixels
     * @param hint one of the rendering hints that corresponds to
     *    {@link java.awt.RenderingHints.KEY_INTERPOLATION} (e.g.
     *    {@link java.awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR},
     *    {@link java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR},
     *    {@link java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC})
     * @return a scaled version of the original {@code BufferedImage}
     */
    public static BufferedImage rescaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint) {
        if (img == null)
            throw new NullPointerException("Invalid (null) image specified");
        BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = tmp.createGraphics();
        if (hint != null)
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
        g2.drawImage(img, 0, 0, targetWidth, targetHeight, null);
        g2.dispose();
        return tmp;
    }
}

Related

  1. maybeGrow(List l, int size)
  2. needsThumbnail(BufferedImage image, int newSize)
  3. newArgbBufferedImage(int width, int height)
  4. overlapsPoints(BufferedImage inImage, int inX, int inY, int inWidth, int inHeight, Color inTextColour)
  5. pack(List buffers, int elements, int size)
  6. rightSize(ByteBuffer in)
  7. sameSize(BufferedImage im1, BufferedImage im2)
  8. scanForDuplicates(BufferedImage leftImage, BufferedImage[] images, int i, int[] order, int width, int height)
  9. sizeOfBytes(ByteBuffer bytes)