andy_baptiste
asked on
Error when loading image with Java: javax.imageio.IIOException: Unsupported Image Type
Hi,
I keep getting errors when loading certain images with Java:
javax.imageio.IIOException : Unsupported Image Type
I think it because the images are CMYK rather than RGB so I installed JAI and grabbed the attached code from the imternet...but STILL getting errors as below:
javax.imageio.IIOException : Unsupported Image Type
at com.sun.imageio.plugins.jp eg.JPEGIma geReader.r eadInterna l(Unknown Source)
at com.sun.imageio.plugins.jp eg.JPEGIma geReader.r ead(Unknow n Source)
at javax.imageio.ImageIO.read (Unknown Source)
at javax.imageio.ImageIO.read (Unknown Source)
Any ideas what I might be doing wrong?
I keep getting errors when loading certain images with Java:
javax.imageio.IIOException
I think it because the images are CMYK rather than RGB so I installed JAI and grabbed the attached code from the imternet...but STILL getting errors as below:
javax.imageio.IIOException
at com.sun.imageio.plugins.jp
at com.sun.imageio.plugins.jp
at javax.imageio.ImageIO.read
at javax.imageio.ImageIO.read
Any ideas what I might be doing wrong?
private static String cmyk2rgb(String filename) throws IOException
{
String rgbFilename = filename;
try{
// Change this format into any ImageIO supported format.
String format = "JPG";
File imageFile = new File(filename);
BufferedImage image = ImageIO.read(imageFile);
if (image != null)
{
int colorSpaceType = image.getColorModel().getColorSpace().getType();
if (colorSpaceType == ColorSpace.TYPE_CMYK)
{
BufferedImage rgbImage = new BufferedImage( image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(image, rgbImage);
rgbFilename = imageFile.getName();
rgbFilename = new File(imageFile.getParent(), format + "_" + rgbFilename).getPath();
ImageIO.write(rgbImage, format, new File(rgbFilename));
}
}
}catch(Exception e){e.printStackTrace();}
return rgbFilename;
}
private static boolean isCMYK(String filename)
{
boolean result = false;
BufferedImage img = null;
try
{
img = ImageIO.read(new File(filename));
}catch (IOException e){return true;}
if (img != null)
{
int colorSpaceType = img.getColorModel().getColorSpace().getType();
result = colorSpaceType == ColorSpace.TYPE_CMYK;
}
return result;
}
JPEG/CMYK are not supported afaik (so you cannot use ImageIO to read them)
Please attach an image that you're having problems with
ASKER
Hi Objects/CEHJ,
Just to confirm....yes the image is a CMYK one created with Photoshop, so that does seem to be the issue.
I was told the code attached would identify these types of images and save them as RGB types, but no joy.
Any ideas how I can achieve converting these images in Java?
Just to confirm....yes the image is a CMYK one created with Photoshop, so that does seem to be the issue.
I was told the code attached would identify these types of images and save them as RGB types, but no joy.
Any ideas how I can achieve converting these images in Java?
Can't really say without an image
ASKER
There you go....
097335.jpg
097335.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi yes as my post said I have already installed JAI, but it was still falling over when I tried to open a CMYK image saved in Photoshop.
I think I have identified the problem now...my IDE (eclipse) was not using the JDK that the extentions were installed in.
The problem I now have is that it will only work from the machine that I installed JAI on.
Does anyone know how I can distribute a Java application that uses Jai ( and the native DLLs )?
I think I have identified the problem now...my IDE (eclipse) was not using the JDK that the extentions were installed in.
The problem I now have is that it will only work from the machine that I installed JAI on.
Does anyone know how I can distribute a Java application that uses Jai ( and the native DLLs )?
>>Hi yes as my post said I have already installed JAI,
That's not JAI in my link. It's JAI ImageIO. Tried it with your image - works fine
That's not JAI in my link. It's JAI ImageIO. Tried it with your image - works fine
ASKER
Sorry.
So is there a way I can deploy the now working application including the DLL's?
The generated jar file doesn't seem to include the DLL's.
So is there a way I can deploy the now working application including the DLL's?
The generated jar file doesn't seem to include the DLL's.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many Thanks.
In the end I deployed it as a folder with the generated jar file, an exe that runs the jar file, and bundled a JRE that had the DLLs in.
In the end I deployed it as a folder with the generated jar file, an exe that runs the jar file, and bundled a JRE that had the DLLs in.
:-)