Java BufferedImage Load loadImage(final URL urlToImage)

Here you can find the source of loadImage(final URL urlToImage)

Description

Load image with URL.

License

Open Source License

Parameter

Parameter Description
urlToImage the url to the image file

Return

BufferedImage if succeed null if fails

Declaration

public static BufferedImage loadImage(final URL urlToImage) 

Method Source Code

//package com.java2s;
/**//from   ww w .  j av a  2s. c  om
 *
 * Open Realm of Stars Game Project
 * Copyright (C) 2016  Tuomo Untinen
 *
 * 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, see http://www.gnu.org/licenses/
 *
 *
 * Generic IO Utilities
 *
 */

import java.awt.image.BufferedImage;

import java.io.IOException;

import java.net.URL;

import javax.imageio.ImageIO;

public class Main {
    /**
     * Load image with URL. Can be used to read images inside JAR file
     * @param urlToImage the url to the image file
     * @return BufferedImage if succeed null if fails
     */
    public static BufferedImage loadImage(final URL urlToImage) {
        try {
            return ImageIO.read(urlToImage);
        } catch (IOException e) {
            System.err.print(urlToImage.toString() + " not found!");
            return null;
        }
    }
}

Related

  1. loadImage(final File refDirectory, final String imageFileName)
  2. loadImage(final String fileName)
  3. loadImage(final String iconFile)
  4. loadImage(final String imagePathname, final Class relatedClass)
  5. loadImage(final String path)
  6. loadImage(Image image)
  7. loadImage(InputStream inputStream)
  8. loadImage(Object whoOrders, String name)
  9. loadImage(String classRelativeFile)