Java Image to BufferedImage getBufferedImage(Image img)

Here you can find the source of getBufferedImage(Image img)

Description

get Buffered Image

License

Open Source License

Declaration

public static BufferedImage getBufferedImage(Image img) 

Method Source Code


//package com.java2s;
/*/*from  ww w  . j  a v  a  2s. co  m*/
 * Copyright (C) 2012 Thedeath<www.fseek.org>
 *
 * 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.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage getBufferedImage(Image img) {
        if (img == null) {
            return null;
        }
        int w = img.getWidth(null);
        int h = img.getHeight(null);
        // draw original image to thumbnail image object and
        // scale it to the new size on-the-fly
        BufferedImage bufimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = bufimg.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        return bufimg;
    }
}

Related

  1. convertToBufferedImage(Image image)
  2. getBufferedImage(Image image)
  3. getBufferedImage(Image image)
  4. getBufferedImage(Image image)
  5. getBufferedImage(Image image)
  6. getBufferedImage(java.awt.Image image)
  7. getScaledBufferedImage(Image icon, double scale)
  8. imageToBufferedImage(Image image)
  9. ImageToBufferedImage(Image image, int width, int height)