Java BufferedImage Create getBufferedImaged(Image img, int width, int height)

Here you can find the source of getBufferedImaged(Image img, int width, int height)

Description

This method is used for converting a java.awt.image.Image to scaled BufferedImage of desired width and height.

License

Open Source License

Parameter

Parameter Description
img a parameter
height a parameter
width a parameter

Declaration

public static BufferedImage getBufferedImaged(Image img, int width, int height) 

Method Source Code

//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;
    }
}

Related

  1. getBufferedImage(File file)
  2. getBufferedImage(String imageFile, Component c)
  3. getBufferedImage(String imagePath)
  4. getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)
  5. getBufferedImageBytes(BufferedImage bufferedImage)
  6. getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height)
  7. getBufferedImageFromFile(String fileName)
  8. getBufferedImageFromPath(String path)
  9. getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2, int yImage2)