Here you can find the source of loadImage(final URL urlToImage)
Parameter | Description |
---|---|
urlToImage | the url to the image file |
public static BufferedImage loadImage(final URL urlToImage)
//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; } } }