Java ImageIcon to BufferedImage imageToBufferedImage(ImageIcon src)

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

Description

image To Buffered Image

License

Open Source License

Declaration

public static BufferedImage imageToBufferedImage(ImageIcon 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  www .jav a2s  .c  o m
            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. getBufferedImage(final ImageIcon icon)
  2. getBufferedImage(ImageIcon icon)
  3. getBufferedImageFitToWidth(ImageIcon icon, double width)
  4. imageIconToBufferedImage(ImageIcon icon)