Java Utililty Methods ImageIcon to BufferedImage

List of utility methods to do ImageIcon to BufferedImage

Description

The list of methods to do ImageIcon to BufferedImage are organized into topic(s).

Method

BufferedImagegetBufferedImage(final ImageIcon icon)
Gets a scaled icon and if it doesn't exist it creates one and scales it
Image imgMemory = icon.getImage();
imgMemory = new ImageIcon(imgMemory).getImage();
int w = icon.getIconWidth();
int h = icon.getIconHeight();
BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(imgMemory, 0, 0, w, h, 0, 0, w, h, null);
...
BufferedImagegetBufferedImage(ImageIcon icon)
get Buffered Image
BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
ig2.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), null);
return bi;
BufferedImagegetBufferedImageFitToWidth(ImageIcon icon, double width)
get Buffered Image Fit To Width
double originalWidth = icon.getIconWidth();
double scale = width / originalWidth;
return getScaledBufferedImage(icon, scale);
BufferedImageimageIconToBufferedImage(ImageIcon icon)
image Icon To Buffered Image
BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics graphics = bufferedImage.createGraphics();
icon.paintIcon(null, graphics, 0, 0);
graphics.dispose();
return bufferedImage;
BufferedImageimageToBufferedImage(ImageIcon src)
image To Buffered Image
return imageToBufferedImage(src.getImage());