简体   繁体   中英

Display Image from Server in Java

I am new in Java programming. My query is that I am having an image which is present on a server and I want to display that image inside the JFrame . I tried using the Image class but that seems to be not working.

Please Note: I don't want to use applets for this, so is there some other method by which this can be done?

Thanks & Regards,

Assuming that it's a public accessible webserver, you can use URL#openStream() to get an InputStream out of an URL .

InputStream input = new URL("http://example.com/image.png").openStream();

Then you can just create the BufferedImage with help of ImageIO#read() the usual way.

BufferedImage image = ImageIO.read(input);
// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM