Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read an ico format picture in java?

Tags:

java

image

ico

I have a lot of .ico formatted pictures, and I want to use them in my Java SE project, but it doesn't know the format. How can I work around this?

like image 494
victorio Avatar asked Jul 09 '12 18:07

victorio


People also ask

What is the ICO image size?

Short answer: 16 x 16 pixels. Long answer: . ico files can actually contain multiple images, at multiple colour depths - you can provide 16x16, 32x32, 48x48 and 64x64 in a single file and the OS will pick the best one to show.


2 Answers

Try out image4j - Image Library for Java

The image4j library allows you to read and write certain image formats in 100% pure Java.

Currently the following formats are supported:

  • BMP (Microsoft bitmap format - uncompressed; 1, 4, 8, 24 and 32 bit)
  • ICO (Microsoft icon format - 1, 4, 8, 24 and 32 bit [XP uncompressed, Vista compressed])

With the library you can easily decode your ico file

List<BufferedImage> image = ICODecoder.read(new File("input.ico"));
like image 87
Konrad Reiche Avatar answered Sep 29 '22 09:09

Konrad Reiche


Apache Commons Imaging allows to read and write ICO files:

    List<BufferedImage> images = Imaging.getAllBufferedImages(new File("input.ico"));

It supports several popular formats of metadata too (EXIF, IPTC and XMP).

TwelveMonkeys ImageIO allows to extend the ImageIO API to support ICO and numerous other image file formats.

like image 35
gouessej Avatar answered Oct 01 '22 09:10

gouessej