File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How can I get a web site's favicon? 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 can I get a web site Watch "How can I get a web site New topic

How can I get a web site's favicon?

Constantine Mosch

Joined: Jan 20, 2013
Posts: 10
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
and gif format
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
I read that it is difficult to get the format of a buffered image.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Jan 20, 2013
Posts: 10
@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?

@Campell Ritchie
I post my topic at "Beginning Java" because I am beginner.
Here, I hope someone can help me!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46360
Welcome to the Ranch
I am moving this discussion as it is too difficult for the “beginning” forum.
I agree. Here's the link:
subject: How can I get a web site's favicon?
It's not a secret anymore!