Java ByteBuffer Size generateScaledImage(final BufferedImage bufImg, @SuppressWarnings("unused") final Object hintsArg, final int size)

Here you can find the source of generateScaledImage(final BufferedImage bufImg, @SuppressWarnings("unused") final Object hintsArg, final int size)

Description

generate Scaled Image

License

Open Source License

Parameter

Parameter Description
bufImg a parameter
size a parameter

Declaration

public static BufferedImage generateScaledImage(final BufferedImage bufImg,
        @SuppressWarnings("unused") final Object hintsArg, final int size) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2015, University of Kansas Center for Research
 * /*from w  w w  .  j  a  va2 s .  c om*/
 * Specify Software Project, specify@ku.edu, Biodiversity Institute,
 * 1345 Jayhawk Boulevard, Lawrence, Kansas, 66045, USA
 * 
 * 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.image.BufferedImage;

public class Main {
    /**
     * @param bufImg
     * @param size
     * @return
     */
    public static BufferedImage generateScaledImage(final BufferedImage bufImg,
            @SuppressWarnings("unused") final Object hintsArg, final int size) {
        BufferedImage sourceImage = bufImg;
        int srcWidth = sourceImage.getWidth();
        int srcHeight = sourceImage.getHeight();

        double longSideForSource = Math.max(srcWidth, srcHeight);
        double longSideForDest = size;

        double multiplier = longSideForDest / longSideForSource;
        int destWidth = (int) (srcWidth * multiplier);
        int destHeight = (int) (srcHeight * multiplier);

        BufferedImage destImage = null;

        destImage = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics2D = destImage.createGraphics();
        graphics2D.drawImage(sourceImage, 0, 0, destWidth, destHeight, null);
        graphics2D.dispose();

        return destImage;
    }
}

Related

  1. ensureBufferCapacity(final int width, final int height, BufferedImage img)
  2. erodeImage(final BufferedImage img, int structElementWidth, int structElementHeight, final int rgbForegroundColor, final int rgbBackgroundColor)
  3. findNewHeight(BufferedImage origImage, double newWidth)
  4. FindResolution(BufferedImage img, double print_width, double print_height)
  5. fitToSize(BufferedImage source, int targetWidth, int targetHeight)
  6. makeBrighterRectangleOnImage(BufferedImage image, int leftPosition, int topPosition, int width, int height, double scaleFactor, Color borderColor, Stroke borderStroke)
  7. makeOval(BufferedImage input, int width, int height)
  8. makeTarget(BufferedImage image, int x, int y, int width, int height)
  9. mapByteBuffer(File cachedFile, int cacheFileSize)