Here you can find the source of iconToImage(Icon icon)
Parameter | Description |
---|---|
icon | a parameter |
public static BufferedImage iconToImage(Icon icon)
//package com.java2s; /*/*from w w w.j a v a2s. com*/ This file is part of Subclient. Subclient 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. Subclient 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 Subclient. If not, see <http://www.gnu.org/licenses/>. Copyright 2012, 2013 Alejandro Celaya Alastru? */ import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.Icon; public class Main { /** * Converts a Icon into a BufferedImage * @param icon * @return */ public static BufferedImage iconToImage(Icon icon) { BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); // Paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0, 0); g.dispose(); return image; } }