Java BufferedImage Load loadImageRessource(Object source, String file)

Here you can find the source of loadImageRessource(Object source, String file)

Description

Load image ressource.

License

Open Source License

Parameter

Parameter Description
source the source
file the file

Return

the buffered image

Declaration

public static BufferedImage loadImageRessource(Object source, String file) 

Method Source Code

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

    }
}

Related

  1. loadImageFromFile(String filepath)
  2. loadImageFromFile_ORIG(String imgName)
  3. loadImagefromJar(Object refObj, String fileName)
  4. loadImageFromURL(String imageURL, Component component)
  5. loadImageFromVisualgorithmJar(String imageFileName)
  6. loadImages(Image[] images, Component comp)
  7. loadImagesForVVPAT(File ballotFile)
  8. loadResource(String file)