Java AWT BufferedImage load from URL

Description

Java AWT BufferedImage load from URL



//package com.demo2s;

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 {/*  ww w. ja va 2 s .c  o m*/
            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;
    }
}



PreviousNext

Related