Java ImageIcon createTempImage(ImageIcon icon, File oldFile)

Here you can find the source of createTempImage(ImageIcon icon, File oldFile)

Description

create Temp Image

License

Open Source License

Declaration

public static File createTempImage(ImageIcon icon, File oldFile) 

Method Source Code

//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;
    }
}

Related

  1. createMonoColoredImageIcon(final Paint paint, final int width, final int height)
  2. createNonCachedImageIcon(File file)
  3. createOverlayIcon(Icon baseIcon, ImageIcon overlayIcon)
  4. createScaledImageIcon(byte[] albumArtBytes)
  5. CreateSizedImageIconScaledSmooth(URL filePath, int width, int height)
  6. displayImage(final ImageIcon ii)
  7. drawImageBorder(Graphics g, ImageIcon img, Rectangle rect, Insets ins, boolean drawCenter)
  8. drawImageBorder(Graphics g, ImageIcon img, Rectangle rect, Insets ins, boolean drawCenter)
  9. fitIcon(ImageIcon icon, int containerWidth, int containerHeight)