Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I get a web site's favicon?

 
Constantine Mosch
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for my bad english.
I want to get the favicon of a web page and to set as ImageIcon on a jLabel.
ImageIcon needs GIF, JPEG or PNG image format.
Favicon is ico format and I use image4j library.

But I found favicon of PNG format http://www.facebook.com/favicon.ico
and gif format http://pixmania.pan.e-merchant.com/grafx/favicon.ico
The previous code doesn't work.

Then I use ByteArrayOutputStream. This code works ONLY for gif or png format.
If image is ico format I don't see the ico on the jLabel.

Why the code with ByteArrayOutputStream doesn't work for all image format?

Are there another way to get the favicon (all formats) with one method?
From here http://www.coderanch.com/t/416158/GUI/java/format-mime-type-PNG-JPG
I read that it is difficult to get the format of a buffered image.





 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's got nothing to do with ByteArrayOutputStream, or with how you're obtaining the image. The javadocs of the ImageIcon state clearly that it works with GIF, JPEG and PNG images - not ICO.

You can use the JIMI library to read ICO files and then write them in a format ImageIcon can handle.
 
Constantine Mosch
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf Dittmer
Thanks for your reply.

I am trying to get the favicon with getImage(URL) method.


I have an exception


From Jimi docs:
"The getImageProducer methods are provided for those wishing to avoid the overhead of having an Image object created for the decoded image."

I am beginner and I don't know how to work with ImageProducer and flags(asynchronous,synchronous, ...)

Can you suggest me a tutorial about loading-saving images with Jimi?

EDIT
@Campell Ritchie
I post my topic at "Beginning Java" because I am beginner.
Here, I hope someone can help me!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
I am moving this discussion as it is too difficult for the “beginning” forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic