Java read different type of image formats jpg,tif,gif,png
Asked Answered
H

3

2

I am trying to read some image files jpg, tif, gif, png and need to save files and create icons. And i am getting UnsupportedTypeException.

ImageIO.read(file);

If i use following line, as earlier discuss in form.

BufferedImage img = JPEGCodec.createJPEGDecoder(inputStream).decodeAsBufferedImage();

I get JPEGCodec cannot found symbol.

I am using netbean 7.0.1. I have also added jai-imageio.jar.

Habitat answered 2/2, 2012 at 11:1 Comment(2)
Have you imported com.sun.image.codec.jpeg.JPEGCodec ??Resolution
Did you follow the JAI-ImageIO installation instructions? I'm pretty sure there was something more that you had to do besides adding jai-imageio.jar to classpath.Zebedee
M
0

By default, ImageIO can only read JPG, GIF and PNG file formats, if I remember right. To add new formats like TIFF, you need to add a plugin, which is a jar file, to your classpath, and to add an ImageIO.scanForPlugins() to you code before you try to read a file.

Example of plugin:

http://ij-plugins.sourceforge.net/plugins/imageio/

Try "ImageIO plugins" in Google.

Mell answered 2/2, 2012 at 11:20 Comment(3)
There are many jpg files that are not readable with imageio. I read somewhere that CMYK format of jpg cannot readable by image io.Habitat
That's possible. Maybe with a specific plugin?Mell
Below is my code. Sometime it load jpg image, then i load another tiff image. If i now again read first image it states Unsupported type. I need simple resize and create icon. ImageIO.scanForPlugins(); BufferedImage image= ImageIO.read(file1);Habitat
Z
0

JAI-ImageIO does include plugins for file formats like TIFF, so in principal what you are trying to do should work. However, to install JAI-ImageIO it's not enough to add it to your classpath. See the complete installation instructions here: http://java.sun.com/products/java-media/jai/INSTALL-jai_imageio_1_0_01.html

Zebedee answered 2/2, 2012 at 11:38 Comment(1)
I have tried to follow the steps. Below is my code. Sometime it load jpg image, then i load another tiff image. If i now again read first image it states Unsupported type. I need simple resize and create icon. ImageIO.scanForPlugins(); BufferedImage image= ImageIO.read(file1);Habitat
H
0

Fr detail we can see the like http://www.randelshofer.ch/blog/2011/08/reading-cmyk-jpeg-images-with-java-imageio/

Image img = null;
ImageInputStream iis = new FileImageInputStream(file);
try {
    for (Iterator<ImageReader> i = ImageIO.getImageReaders(iis);
         img == null && i.hasNext(); ) {
        ImageReader r = i.next();
        try {
            r.setInput(iis);
            img = r.read(0);
        } catch (IOException e) {}
    }
} finally {
    iis.close();
}
return img;

Java advance image io also solve the problem, but its hard to maintain to install on all plateform.

Habitat answered 6/2, 2012 at 6:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.