Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   ImageIO: Read JPG image from URL with header: referer? (http://www.velocityreviews.com/forums/t141080-imageio-read-jpg-image-from-url-with-header-referer.html)

Rune 02-16-2005 10:40 AM

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?



Roland 02-16-2005 11:12 AM

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_/ /__/
/ \ /_/ / \

Thomas Weidenfeller 02-16-2005 11:13 AM

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

Rune 02-16-2005 01:07 PM

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.



Rune 02-16-2005 01:08 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57