Here you can find the source of convert(ImageIcon icon)
Parameter | Description |
---|---|
icon | the ImageIcon to be converted |
public final static BufferedImage convert(ImageIcon icon)
//package com.java2s; /**//from ww w . j ava2s . c om * This file is part of evdev-java - Java implementation. * * evdev-java - Java implementation 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. * * evdev-java - Java implementation 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 evdev-java - Java implementation. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; public class Main { /** * Convert the Input {@link ImageIcon} into a {@link BufferedImage} with type TYPE_INT_ARGB * * @param icon the {@link ImageIcon} to be converted * @return the converted BufferedImaged */ public final static BufferedImage convert(ImageIcon icon) { if (icon == null) { throw new IllegalArgumentException("ImageIcon is null"); } BufferedImage buffered = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = buffered.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); // paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0, 0); g.dispose(); return buffered; } }