Java BufferedImage from URL urlToImage(String urlstring)

Here you can find the source of urlToImage(String urlstring)

Description

url To Image

License

Open Source License

Parameter

Parameter Description
urlstring The url of the image.

Return

Image object.

Declaration

public static Image urlToImage(String urlstring) 

Method Source Code

//package com.java2s;
/*/*from  ww  w. ja  v  a 2s . c  o  m*/
 * This file is part of CraftCommons.
 *
 * Copyright (c) 2011 CraftFire <http://www.craftfire.com/>
 * CraftCommons is licensed under the GNU Lesser General Public License.
 *
 * CraftCommons is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CraftCommons 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Image;
import java.awt.Toolkit;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**
     * @param urlstring The url of the image.
     * @return Image object.
     */
    public static Image urlToImage(String urlstring) {
        try {
            URL url = new URL(urlstring);
            return Toolkit.getDefaultToolkit().createImage(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. downloadImage(String url)
  2. downloadImage(URL url)
  3. getFileAndDownload(String urlString, String folder)
  4. httpGetImage(String url)
  5. Img2ByteByUrl(String strUrl)
  6. urlToImage(URL imageUrl)
  7. urlToJpegThumbnail(String url, String filename, double maxWidth, double maxHeight)