Java Image to BufferedImage imageToBufferedImage(Image src)

Here you can find the source of imageToBufferedImage(Image src)

Description

image To Buffered Image

License

Open Source License

Declaration

public static BufferedImage imageToBufferedImage(Image src) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;

public class Main {

    public static BufferedImage imageToBufferedImage(Image src) {
        int width = 0;
        int height = 0;

        if (src != null) {
            width = src.getWidth(null);/*from w w w .java 2  s.c  om*/
            height = src.getHeight(null);
        }

        BufferedImage image = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_BGR);
        Graphics2D g = image.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g.drawImage(src, 0, 0, null);
        g.dispose();

        return image;
    }

    public static BufferedImage imageToBufferedImage(ImageIcon src) {
        return imageToBufferedImage(src.getImage());
    }
}

Related

  1. imageToBufferedImage(Image image)
  2. ImageToBufferedImage(Image image, int width, int height)
  3. imageToBufferedImage(Image img)
  4. imageToBufferedImage(Image img)
  5. imageToBufferedImage(Image pImage)
  6. makeBufferedImage(final Image image)
  7. makeBufferedImage(Image image)
  8. makeBufferedImage(Image image)
  9. makeRGBABufferedImageFromImage( Image image)