Here you can find the source of loadImageRessource(Object source, String file)
Parameter | Description |
---|---|
source | the source |
file | the file |
public static BufferedImage loadImageRessource(Object source, String file)
//package com.java2s; /*//from www.j a va 2s. c o m This file is part of PSFj. PSFj 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. PSFj 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 PSFj. If not, see <http://www.gnu.org/licenses/>. Copyright 2013,2014 Cyril MONGIS, Patrick Theer, Michael Knop */ import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; public class Main { /** * Load image ressource. * * @param source * the source * @param file * the file * @return the buffered image */ public static BufferedImage loadImageRessource(Object source, String file) { BufferedImage image = null; try { image = ImageIO.read(source.getClass().getResource(file)); } catch (IOException ioe) { System.out.println(ioe.getMessage()); try { image = ImageIO.read(source.getClass().getResource("src" + file)); } catch (IOException e) { System.out.println(e.getMessage()); } } return image; } }