File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
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
Author

How can I get a web site's favicon?

Constantine Mosch
Greenhorn

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 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
Marshal

Joined: Mar 22, 2005
Posts: 42592
    
  65
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.


Ping & DNS - my free Android networking tools app
Constantine Mosch
Greenhorn

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?

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

Joined: Oct 13, 2005
Posts: 39773
    
  28
Welcome to the Ranch
I am moving this discussion as it is too difficult for the “beginning” forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I get a web site's favicon?