aspose file tools*
The moose likes Java in General and the fly likes How to get an image from an http address into Image object directly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get an image from an http address into Image object directly" Watch "How to get an image from an http address into Image object directly" New topic
Author

How to get an image from an http address into Image object directly

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Hi,
I want to load an image present in an http address and put it in java.awt.image .
I used something like :

but the image is always null, even though the image exist in that url
I again tried this code:

But problem is , when we call in.available(), only a small amount of data has reached us and so only a small portion of the image is obtained (and displayed if I try to do a g.drawImage(..)).
How do I obtain the whole image data?
In short I need a code to get an image from any http site.
Thanks in advance
Tanveer
[ February 20, 2004: Message edited by: Tanveer Rameez ]
[ February 20, 2004: Message edited by: Tanveer Rameez ]

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Did you try looking at the documentation for java.awt.Toolkit?
The Toolkit.getImage(String) method takes the name of a file. Not a url. The Toolkit.getImage(java.net.URL) method is appropriate what you are trying to do.
When you were having problems with InputStream.available(), did you try looking at the documentation?
If you did, you'd see that available() doesn't return the file size, it returns ". . . the number of bytes that can be read (or skipped over) from this input stream without blocking".


[How To Ask Questions On JavaRanch]
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Originally posted by Joe Ess:
Did you try looking at the documentation for java.awt.Toolkit?
The Toolkit.getImage(String) method takes the name of a file. Not a url. The Toolkit.getImage(java.net.URL) method is appropriate what you are trying to do.
When you were having problems with InputStream.available(), did you try looking at the documentation?
If you did, you'd see that available() doesn't return the file size, it returns ". . . the number of bytes that can be read (or skipped over) from this input stream without blocking".

Hi
Thanks for the reply. Yes, how silly of my to use a String when i should be using an url.
..silly mistake !!!
Tanveer
[ February 21, 2004: Message edited by: Tanveer Rameez ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get an image from an http address into Image object directly