Here you can find the source of setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage)
public static Dimension setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage)
//package com.java2s; /** This file is part of Approach Avoidance Task. * * Approach Avoidance Task 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 3 of the License, or * (at your option) any later version./*w w w . ja v a2 s . c o m*/ * * Approach Avoidance Task 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 Approach Avoidance Task. If not, see <http://www.gnu.org/licenses/>. * */ import java.awt.*; import java.awt.image.BufferedImage; public class Main { /** * Geeft de waarden imgBorderWidth, imgSizeX & imgSizeY welke door imageShow() gebruikt worden. */ //TODO dit veranderen public static Dimension setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int newWidth, newHeight; int resize = size - centerPos; double resizeFactor; int maxscreenSize = (int) (screen.getHeight() * maxSizePercentage) / 100; if (image.getWidth() >= image.getHeight()) {//Landscape resizeFactor = (maxscreenSize - image.getWidth()) / centerPos; newWidth = (int) (image.getWidth() + resize * resizeFactor); float f = (float) newWidth / (float) image.getWidth(); newHeight = (int) (image.getHeight() * f); } else { resizeFactor = (maxscreenSize - image.getHeight()) / centerPos; newHeight = (int) (image.getHeight() + resize * resizeFactor); float f = (float) newHeight / (float) image.getHeight(); newWidth = (int) (image.getWidth() * f); } return new Dimension(newWidth, newHeight); } }