Java ByteBuffer Resize performResize(BufferedImage source, int newWidth, int newHeight)

Here you can find the source of performResize(BufferedImage source, int newWidth, int newHeight)

Description

Resizes an image using nearest filtering.

License

Open Source License

Parameter

Parameter Description
source the source image.
newWidth the new image width.
newHeight the new image height.

Declaration

public static BufferedImage performResize(BufferedImage source,
        int newWidth, int newHeight) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Black Rook Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 ******************************************************************************/

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Main {
    /**/*from   w ww .  j a  va 2 s  . c  o m*/
     * Resizes an image using nearest filtering.
     * @param source   the source image.
     * @param newWidth   the new image width.
     * @param newHeight   the new image height.
     */
    public static BufferedImage performResize(BufferedImage source,
            int newWidth, int newHeight) {
        BufferedImage out = new BufferedImage(newWidth, newHeight,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = out.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_OFF);
        g2d.drawImage(source, 0, 0, newWidth, newHeight, null);
        g2d.dispose();
        return out;
    }
}

Related

  1. check(BufferedImage image, int resizeWidth, int resizeHeight)
  2. increaseBufferCapatity(ByteBuffer byteBuffer)
  3. increaseByteBuffer(ByteBuffer byteBuffer, int increase)
  4. resize(ByteBuffer buffer)
  5. resize(ByteBuffer oldBuffer, int newSize)
  6. resizeBuffer(final ByteBuffer in)
  7. resizeByteBuffer(ByteBuffer buf, long size)