Reputation: 5032
I try to read a JPEG file with ImageIO.read() but for this image it give me a CMMException. after read this and this I understand ImageIO can't read some kind of jpeg file.
So I need a solution to read all kind of images. JAI library look to be a dead library. And I don't undestrand how TwelveMonkeys works. So if someone have explainations about it or another alternative, I'll take it. Thank's
Upvotes: 1
Views: 1296
Reputation: 27113
For reading most JPEGs (even those that that cause CMMException
s), you can use ImageIO and TwelveMonkeys ImageIO plug-ins. To do so, add the following dependency to your Maven project:
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.0</version>
If you already use ImageIO to read images, there's no need to change your code. :-)
To verify that the plugin is installed and used at run-time, you could use the following code:
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
while (readers.hasNext()) {
System.out.println("reader: " + readers.next());
}
The first line should print:
reader: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader@somehash
Upvotes: 6