Java BufferedImage from URL downloadImage(String url)

Here you can find the source of downloadImage(String url)

Description

download Image

License

Open Source License

Declaration

public static BufferedImage downloadImage(String url) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

import java.io.IOException;

import java.net.HttpURLConnection;
import java.net.URL;

import javax.imageio.ImageIO;

public class Main {
    public static BufferedImage downloadImage(String url) {
        HttpURLConnection connection = null;
        try {/*w ww .jav a2s.c om*/
            connection = (HttpURLConnection) new URL(url).openConnection();
            connection.connect();
            BufferedImage image = ImageIO.read(connection.getInputStream());
            connection.disconnect();
            return image;
        } catch (IOException e) {
            e.printStackTrace();
            if (connection != null) {
                connection.disconnect();
            }
            return null;
        }
    }
}

Related

  1. downloadImage(URL url)
  2. getFileAndDownload(String urlString, String folder)
  3. httpGetImage(String url)
  4. Img2ByteByUrl(String strUrl)