Skip to main content

[JAVA2D] ImageIO problem with ICC Profile metadata in JPG

2 replies [Last post]
Anonymous

I have a jpeg image that contains an ICC Profile of Nikon sRGB 4.0.0.3001.
I want to read this image in, perform some JAI operations, and write the
new image out. For some reason, reading the file in and writing it back
out using the ImageIO read and write methods is causing images with this
ICC Profile tag to become significantly darker, where you almost can't
tell what the image even is. If I use Photoshop to remove the ICC Profile
information from my jpeg before running it through this code, the
outputted image looks just fine. Am I doing something wrong? Are there
some kind of colorspace hints or other types of hints I could provide to
the JPEG codec to avoid this problem? The code needs to be able to handle
jpegs both with and without this ICC Profile tag.

Here is the simple code I am running:

public class ImageTester {

public static void main(String args[]) {
if(args.length < 2) {
System.out.println("Usage: ImageTester
");
System.exit(0);
}

try {
FileInputStream fis = new FileInputStream(args[0]);
BufferedImage bImage = ImageIO.read(new FileInputStream(args
[0]));

/* Do some JAI stuff here when I get the ImageIO code to work
*/

FileOutputStream fos = new FileOutputStream(args[1]);
ImageIO.write(bImage, "JPEG", fos);

fis.close();
fos.close();
}
catch(IOException ex) {
ex.printStackTrace();
}

}
}

I can email anyone who is interested my JPEG test images, one with the ICC
Profile and the one where I have removed it.

Thanks,
Julie

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Julie Szmyd

I discovered a couple of workarounds:

- Use JAI to read the image. This works fine.

- Remove the profile info using JMagick(http://www.yeo.id.au/jmagick)
before using ImageIO.read(). Details on using JMagick to do this can be
found at: http://www.yeo.id.au/jmagick/fom-serve/cache/28.html.

--Julie

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

burma

I experienced the same problem with Adobe RGB 98 profiles.
Maybe, you could force the image reader to perform the color conversion
into the standard sRGB colorspace.

Get the reader and the ImageReadParam, and select CS_ sRGB :
...
for (Iterator i = reader.getImageTypes(0); i.hasNext(); ) {
ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
ColorSpace cs = type.getColorModel().getColorSpace() ;
if ( cs.isCS_sRGB() ) {
param.setDestinationType(type);
break ;
}
// exit if not RGB
if ( cs.getType() != ColorSpace.TYPE_RGB ) break ;
}
...

This works for me.

Emmanuel D.

Julie Szmyd wrote:

>I discovered a couple of workarounds:
>
>- Use JAI to read the image. This works fine.
>
>- Remove the profile info using JMagick(http://www.yeo.id.au/jmagick)
>before using ImageIO.read(). Details on using JMagick to do this can be
>found at: http://www.yeo.id.au/jmagick/fom-serve/cache/28.html.
>
>--Julie
>
>===========================================================================
>To unsubscribe, send email to listserv@java.sun.com and include in the body
>of the message "signoff JAVA2D-INTEREST". For general help, send email to
>listserv@java.sun.com and include in the body of the message "help".
>
>
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".