Java Icon to BufferedImage iconToBufferedImage(Icon icon)

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

Description

icon To Buffered Image

License

Open Source License

Declaration

private static BufferedImage iconToBufferedImage(Icon icon) 

Method Source Code


//package com.java2s;
/*//from w w  w  .  ja v  a2s .  c om
 * Copyright (C) 2014 Shashank Tulsyan
 *
 * 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.Color;
import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.Icon;

public class Main {
    private static BufferedImage iconToBufferedImage(Icon icon) {
        BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.createGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
        // paint the Icon to the BufferedImage.
        icon.paintIcon(null, g, 0, 0);
        return bi;
    }
}

Related

  1. getBufferedImage(Component comp, Icon icon)
  2. getBufferedImage(Icon icon)
  3. getBufferedImageFromIcon(Icon icon)
  4. toBufferedImage(Icon icon)
  5. toBufferedImage(Icon icon, int x, int y)