![]() |
ImageIO: Read JPG image from URL with header: referer?
Hi,
I'm trying to make thumbnails of some images on the net. So I though I'd use the ImageIO library. But apparently it only has this method to read images from the net: read(java.net.URL). But I need to set the header referer property on the net connection before reading the image. Which I had done before with the URLConnection object. (e.g. URLConnection urlConn = url.openConnection(); urlConn.setRequestProperty("Referer", referer); urlConn.connect(); ) But ImageIo.read() doesn't accept URLConnection. What do I do? |
Re: ImageIO: Read JPG image from URL with header: referer?
On 16-2-2005 11:40, Rune wrote:
> Hi, > > I'm trying to make thumbnails of some images on the net. So I though I'd use > the ImageIO library. But apparently it only has this method to read images > from the net: read(java.net.URL). But I need to set the header referer > property on the net connection before reading the image. Which I had done > before with the URLConnection object. > > (e.g. > URLConnection urlConn = url.openConnection(); > urlConn.setRequestProperty("Referer", referer); > urlConn.connect(); > ) > > But ImageIo.read() doesn't accept URLConnection. What do I do? > > There's also ImageIO.read(java.io.InputStream). I haven't tried it, but I'd say the following should work: URLConnection urlConn = url.openConnection(); urlConn.setRequestProperty("Referer", referer); urlConn.connect(); InputStream urlStream = urlConn.getInputStream(); image = ImageIO.read(urlStream); -- Regards, Roland de Ruiter ___ ___ /__/ w_/ /__/ / \ /_/ / \ |
Re: ImageIO: Read JPG image from URL with header: referer?
Rune wrote:
> URLConnection urlConn = url.openConnection(); > urlConn.setRequestProperty("Referer", referer); ImageIO.read(urlConn.getInputStream()); /Thomas -- The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq |
Re: ImageIO: Read JPG image from URL with header: referer?
> There's also ImageIO.read(java.io.InputStream). I haven't tried it, but
> I'd say the following should work: > > URLConnection urlConn = url.openConnection(); > urlConn.setRequestProperty("Referer", referer); > urlConn.connect(); > InputStream urlStream = urlConn.getInputStream(); > image = ImageIO.read(urlStream); Works like a charm. Thanks. |
Re: ImageIO: Read JPG image from URL with header: referer?
> ImageIO.read(urlConn.getInputStream());
Yes this works. Thank you. |
| All times are GMT. The time now is 12:54 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.