Here you can find the source of getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType)
Parameter | Description |
---|---|
originalImage | the image to resize |
newWidth | the new imageWidth of the image |
newHeight | the new imageHeight of the image |
imageType | the type of BufferedImage |
public static Image getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType)
//package com.java2s; /******************************************************************************* * Copyright 2013 See AUTHORS file.//from w w w.ja v a 2 s . c om * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage; public class Main { /** * Scales the specified image to the desired dimensions by specified type * and the smooth scaling method * * @param originalImage the image to resize * @param newWidth the new imageWidth of the image * @param newHeight the new imageHeight of the image * @param imageType the type of {@code BufferedImage} * * @return the scaled image */ public static Image getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType) { return getResizedImage(originalImage, newWidth, newHeight, imageType, Image.SCALE_SMOOTH); } /** * Scales the specified image to the desired dimensions by specified type * and the specified scaling method * * @param originalImage the image to resize * @param newWidth the new imageWidth of the image * @param newHeight the new imageHeight of the image * @param imageType the type of {@code BufferedImage} * @param scaleType the method of scaling to use under {@code Image} * * @return the scaled image */ public static Image getResizedImage(Image originalImage, int newWidth, int newHeight, int imageType, int scaleType) { if (originalImage == null) return null; Image temp = originalImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, imageType); Graphics2D g = resizedImage.createGraphics(); g.drawImage(temp, 0, 0, newWidth, newHeight, null); g.dispose(); return resizedImage; } }