从URL中读取图像 [英] reading image from URL
本文介绍了从URL中读取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我执行以下Groovy代码
If I execute the following Groovy code
URL url = new URL('http://glowstick.blisstunes.com/wp-content/plugins/rss-poster/cache/e1ebf_josh-wink.jpg')
ImageIO.read(url)
我得到一个异常:
I get an exception:
javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(ImageIO.java:1369)
但如果我在图像显示的浏览器中访问URL。是因为HTTP请求被阻止,因为它不像(来自头部)看起来像是来自浏览器?
But if I visit the URL in a browser the image displays. Is it because the HTTP request is being blocked because it doesn't look (from the headers) like it's coming from a browser?
推荐答案
<使用这个:
Image image = Toolkit.getDefaultToolkit().createImage(url);
这篇关于从URL中读取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文