load Image from URL - Java 2D Graphics

Java examples for 2D Graphics:Image Load

Description

load Image from URL

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import javax.imageio.ImageIO;

public class Main {
    public static BufferedImage loadImage(URL url) {
        BufferedImage bimg = null;
        try {//www .  jav a2 s  . c om
            bimg = ImageIO.read(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bimg;
    }

    public static BufferedImage loadImage(String url) {
        BufferedImage bimg = null;
        try {
            bimg = ImageIO.read(new File(url));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bimg;
    }
}

Related Tutorials