Java ImageIcon Load readImageIconFromFile(File srcFile)

Here you can find the source of readImageIconFromFile(File srcFile)

Description

Read the image from the given file to an icon image.

License

Open Source License

Parameter

Parameter Description
srcFile The file to read from.

Return

The read icon image or null if something went wrong.

Declaration

public static ImageIcon readImageIconFromFile(File srcFile) 

Method Source Code

//package com.java2s;
/*/*from  www. j  av a2  s.com*/
 * TV-Browser
 * Copyright (C) 04-2003 Martin Oberhauser (martin_oat@yahoo.de)
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * CVS information:
 *  $RCSfile$
 *   $Source$
 *     $Date: 2010-11-21 15:38:33 +0100 (Sun, 21 Nov 2010) $
 *   $Author: bananeweizen $
 * $Revision: 6835 $
 */

import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Main {
    /**
     * Read the image from the given file to an icon image.
     *
     * @param srcFile The file to read from.
     *
     * @return The read icon image or <code>null</code> if something went wrong.
     * @since 2.6
     */
    public static ImageIcon readImageIconFromFile(File srcFile) {
        try {
            return new ImageIcon(ImageIO.read(srcFile));
        } catch (Exception e) {
        }

        return null;
    }
}

Related

  1. loadImageIcon(byte bytes[], String descr)
  2. loadImageIcon(Class clas, String iconPath)
  3. loadImageIcon(String imageName)
  4. loadImageIcon(String url)
  5. loadResourceImageIcon(String imageName)