Java Icon to Image iconToImage(Icon icon)

Here you can find the source of iconToImage(Icon icon)

Description

Convert the given icon to an image.

License

Open Source License

Parameter

Parameter Description
icon the icon to convert.

Return

the converted icon.

Declaration

public static BufferedImage iconToImage(Icon icon) 

Method Source Code

//package com.java2s;
/* /* w  w w . ja v  a  2s .co m*/
 * This file is part of Quelea, free projection software for churches.
 * Copyright (C) 2011 Michael Berry
 * 
 * This program 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.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.image.BufferedImage;

import javax.swing.Icon;

import javax.swing.JLabel;

public class Main {
    /**
     * Convert the given icon to an image.
     *
     * @param icon the icon to convert.
     * @return the converted icon.
     */
    public static BufferedImage iconToImage(Icon icon) {
        BufferedImage ret = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
                BufferedImage.TYPE_INT_RGB);
        icon.paintIcon(new JLabel(), ret.createGraphics(), 0, 0);
        return ret;
    }
}

Related

  1. iconToImage(@Nonnull Component context, @Nullable final Icon icon)
  2. iconToImage(Icon icon)
  3. iconToImage(Icon icon)
  4. iconToImage(Icon icon)
  5. iconToImage(Icon icon)
  6. iconToImage(Icon icon)
  7. iconToImage(Icon icon)
  8. iconToImage(Icon icon)
  9. iconToImage(Icon icon)