Here you can find the source of createTempImage(ImageIcon icon, File oldFile)
public static File createTempImage(ImageIcon icon, File oldFile)
//package com.java2s; /**//from w w w. j ava 2 s . co m * ComicDB - overview you comics * Copyright (C) 2006 Daniel Moos * * 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin * St, Fifth Floor, Boston, MA 02110, USA */ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; public class Main { public static File createTempImage(ImageIcon icon, File oldFile) { String extension = icon.getDescription(); extension = extension.substring(extension.lastIndexOf(".") + 1); try { File ret = File.createTempFile("cdb", "." + extension); ret.deleteOnExit(); BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bi.createGraphics(); g2d.drawImage(icon.getImage(), 0, 0, null); g2d.dispose(); //?? ImageIO.write(bi, extension, ret); return ret; } catch (IOException ioe) { ioe.printStackTrace(); } return null; } }