Here you can find the source of getBufferedImaged(Image img, int width, int height)
Parameter | Description |
---|---|
img | a parameter |
height | a parameter |
width | a parameter |
public static BufferedImage getBufferedImaged(Image img, int width, int height)
//package com.java2s; /*/* w ww . ja va 2s . co m*/ * Copyright (C) 2014. EMBL, European Bioinformatics Institute * * 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 3 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, see <http://www.gnu.org/licenses/>. */ import java.awt.Image; import java.awt.image.BufferedImage; public class Main { /** * This method is used for converting a java.awt.image.Image to scaled * BufferedImage of desired width and height. * * @param img * @param height * @param width * @return */ public static BufferedImage getBufferedImaged(Image img, int width, int height) { Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage bufferedImg = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); bufferedImg.getGraphics().drawImage(image, 0, 0, null); return bufferedImg; } }