• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Destroy anything that stands in your way. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic