how to load a image from web in java

后端 未结 4 2163
[愿得一人]
[愿得一人] 2020-12-28 14:57

I need to load an image from a web in a simple Java stand alone aplication. Any Ideas?

相关标签:
4条回答
  • 2020-12-28 15:29

    You can load an image using

    BufferedImage img = ImageIO.read(new URL("http://stackoverflow.com/content/img/so/logo.png"));
    

    For methods how to display the loaded image, see the Sun "Working with images" tutorial.

    0 讨论(0)
  • 2020-12-28 15:39
    URL url = new URL("http://host/theimage.jpg");
    URLConnection conn = url.openConnection();
    InputStream in = conn.getInputStream();
    

    is that enough to start you? Don't know what you want to do from there.

    0 讨论(0)
  • 2020-12-28 15:47

    I would take a look at HTTPClient.

    Find the URL to the image, and you can get an inputstream feeding you the image data, plus you'll get the content-type etc. so you can correctly handle it once you've downloaded it.

    Here's some sample code. You may also need to call getResponseHeaders() on the GetMethod to identify the image type.

    0 讨论(0)
  • 2020-12-28 15:51

    See the documentation at ImageIO.read(URL).

    0 讨论(0)
提交回复
热议问题