1

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

Community
  • 1
  • 1
agonist_
  • 4,890
  • 6
  • 32
  • 55
  • Hi agonist_, I'm the author of the TwelveMonkeys library. Maybe I can help. :-) – Harald K Sep 12 '13 at 15:40
  • Hi, yes i'm sure you can ! :) as you say here http://stackoverflow.com/questions/4470958/why-does-loading-this-jpg-using-javaio-give-cmmexception you can use TwelveMonkeys just like ImageIO, so which method I have to use to replace ImageIO.read(inpustream) ? – agonist_ Sep 12 '13 at 15:45
  • 1
    It's not "just like ImageIO", it *is* ImageIO (that behind the scenes discovers and uses the plugins). You don't have to change your code. :-) Just make sure you build the TwelveMonkeys project and place all the JARs on the class path, or better, use Maven and depend on the plugins you need. I'm working on the documentation/binary builds, hopefully one day.. ;-) – Harald K Sep 12 '13 at 16:51
  • Thank's for your answer, so if I want all relativ stuff to read image, I need to depends on : com.twelvemonkeys twelvemonkeys-imageio 2.3 ? – agonist_ Sep 13 '13 at 07:20
  • 2.3 is an old version, see answer below. – Harald K Sep 13 '13 at 07:48

1 Answers1

6

For reading most JPEGs (even those that that cause CMMExceptions), 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
Harald K
  • 26,314
  • 7
  • 65
  • 111
  • I add it to my dependency, but I always obtain reader: com.sun.imageio.plugins.jpeg.JPEGImageReader@578ac378 when I execute your code – agonist_ Sep 13 '13 at 08:52
  • For the moment I just try to make it work on a basic program just with a Main class . on Intellij idea with the basic run method? and just twelvemonkeys on dependency – agonist_ Sep 13 '13 at 11:58
  • Ahem.. My bad. :-/ The dependency was incorrect. It should have read `imageio-jpeg`. Fixed now. Update and try again. :-) – Harald K Sep 13 '13 at 12:09
  • 1
    Yeah nice ! that work fine now. All pictures are loaded ! thank's very much for your help :) – agonist_ Sep 13 '13 at 12:51
  • Great! Should you encounter any bugs or JPEGs that can't be read, please use the [issue tracker](https://github.com/haraldk/TwelveMonkeys/issues). – Harald K Sep 13 '13 at 13:15
  • Dependency does not work from public repository. Anybody can point me to jar file to download. I would appreciate it. – Dima Oct 27 '13 at 02:19
  • @Dima You need to download the project and build/install it yourself. There's no official binaries available yet, sorry. Let me know if you have any trouble building. – Harald K Oct 27 '13 at 09:01
  • @haraldK Thanks for your help, I built it and it seems to be working perfectly on my local dev setup (windows), however when I deploy it to server (Centos), it does not see the reader: com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader. Both of them using java 1.7.0_06-b24. Any clue ? – Dima Dec 10 '13 at 02:18
  • @Dima Hmm.. Not without more information. Please file an issue in the [issue tracker](https://github.com/haraldk/TwelveMonkeys/issues) with as much relevant information about your system as possible, and I'll have a look at it. – Harald K Dec 10 '13 at 19:59
  • Updated with latest release (no longer necessary to build yourself). – Harald K Nov 26 '14 at 14:25