Skip to main content

Support for writing metadata in JPEG files

4 replies [Last post]
enrictordera
Offline
Joined: 2006-12-31

As far as I know, current JAI ImageIO Tools version (1.1) JPEG ImageWriter does not support writing metadata.

I would like to read some JPEG images, apply some image processing and then write them back keeping their original metadata. Right now I cant get it done because of lack of support for writing JPEG metadata in JAI ImageIO Tools. The same code works fine when dealing with TIFF files.

Does anybody know if there will be soon some version capable of writing metadata in JPEG files? Is there any other workaround, another open library?

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23

If you are using JAI Image I/O Tools you should be able to detect two JPEG writers: one from JAI Image I/O Tools and one from Java SE. The latter supports writing image metadata. So if you make sure to pick up that writer then you should be able to work ...

> As far as I know, current JAI ImageIO Tools version
> (1.1) JPEG ImageWriter does not support writing
> metadata.
>
> I would like to read some JPEG images, apply some
> image processing and then write them back keeping
> their original metadata. Right now I cant get it done
> because of lack of support for writing JPEG metadata
> in JAI ImageIO Tools. The same code works fine when
> dealing with TIFF files.
>
> Does anybody know if there will be soon some version
> capable of writing metadata in JPEG files? Is there
> any other workaround, another open library?
>
> Thanks in advance

bwy
Offline
Joined: 2003-09-23
Ken Warner

I've just started learning Eclipse. So I thought a good way to do that would be to build a little applet that opens and reads image files. And that made me think that it would also be a good time to catch up with ImageIO. I haven't played with it for a while.

So I'm using Java 1.5.x and ImageIO 1.1. I want to read a .j2c file which is a variant of a JPEG2000 image file. A j2c file is just the codestream part of a JPEG2000 file -- just the wavelet encoded image.

So I'm using the Java ImageI/O API Guide which was written a long time ago -- 2001:

http://java.sun.com/javase/6/docs/technotes/guides/imageio/spec/title.fm...

And I'm stepping though the simple tutorial. I get this far (see snipit below) -- but j2c is not one of the accepted names for the readers.

Which reader should I ask for to read a j2c file?

And why did you make it so hard to get a list of all the acceptable query string that can be used as an argument for ImageIO.getImageReadersByFormatName(s). It returns an Iterator that lists the names that would be appropriate for one particular file type. I've looked and I can't find a general purpose way to list all the acceptable image reader format names. It's a guessing game. If I use "j2c" as an argument ImageIO.getImageReadersByFormatName("j2c") will throw an exception. If I knew what names were acceptable in the first place it would be easier. In Eclipse's debugger I see that for jpeg files "jpeg, jpg, jfif, jpeg-lossless, jpeg-ls (and the all caps versions" are acceptable to getImageReadersByFormatName. No jp2 or j2c. I'm probably the one out of date but in the little work I've done with JPEG2000, those are acceptable file names.

But don't forget my question -- which reader should I ask for to read a j2c file?

private boolean makeImage()
{
boolean status = true;
try
{
ImageInputStream iis = ImageIO.createImageInputStream(imageBuffer);
Iterator readers = ImageIO.getImageReadersByFormatName("j2c");
ImageReader reader = (ImageReader)readers.next();
System.err.println("Got a reader -- " + reader.getFormatName());
}
catch (IllegalArgumentException iae)
{
System.err.println("Illegal Arguement Exception...");
status = false;
}
catch (IOException ioe)
{
System.err.println("IO Exception...");
status = false;
}
return status;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

bpb
Offline
Joined: 2004-06-23

>
> I've just started learning Eclipse. So I thought a
> good way to do that would be to build a little applet
> that opens and reads image files. And that made me
> think that it would also be a good time to catch up
> with ImageIO. I haven't played with it for a while.
>
> So I'm using Java 1.5.x and ImageIO 1.1. I want to
> read a .j2c file which is a variant of a JPEG2000
> image file. A j2c file is just the codestream part
> of a JPEG2000 file -- just the wavelet encoded image.
>
> So I'm using the Java ImageI/O API Guide which was
> written a long time ago -- 2001:
>
> http://java.sun.com/javase/6/docs/technotes/guides/ima
> geio/spec/title.fm.html
>
> And I'm stepping though the simple tutorial. I get
> this far (see snipit below) -- but j2c is not one of
> the accepted names for the readers.
>
> Which reader should I ask for to read a j2c file?

The JPEG 2000 reader. You can use the format names
"JPEG 2000", "JPEG2000", "jpeg 2000", or "jpeg2000".

> And why did you make it so hard to get a list of all
> the acceptable query string that can be used as an
> argument for ImageIO.getImageReadersByFormatName(s).
> It returns an Iterator that lists the names that
> t would be appropriate for one particular file type.
> I've looked and I can't find a general purpose way
> y to list all the acceptable image reader format
> names. It's a guessing game.

You can use the IIORegistry to get all registered ImageReaderSpi instances and then invoke getFormatNames() on each of these to get the supported format names. Same thing for file extensions and MIME types.

> If I use "j2c" as an
> argument ImageIO.getImageReadersByFormatName("j2c")
> will throw an exception.

"j2c" is really a file suffix and it is incorrectly missing from the ImageReaderSpi for JPEG 2000.

> If I knew what names were
> acceptable in the first place it would be easier. In
> Eclipse's debugger I see that for jpeg files "jpeg,
> jpg, jfif, jpeg-lossless, jpeg-ls (and the all caps
> versions" are acceptable to
> getImageReadersByFormatName. No jp2 or j2c. I'm

The JPEG2000 reader is entirely separate from the JPEG reader whereas the latter encompasses lossless JPEG and JPEG-LS.

> probably the one out of date but in the little work
> I've done with JPEG2000, those are acceptable file
> names.
>
> But don't forget my question -- which reader should I
> ask for to read a j2c file?
>
> private boolean makeImage()
> {
> boolean status = true;
> try
> {
> ImageInputStream iis =
> Stream iis =
> ImageIO.createImageInputStream(imageBuffer);
> Iterator readers =
> or readers =
> ImageIO.getImageReadersByFormatName("j2c");

"JPEG2000"

> ImageReader reader =
> der reader = (ImageReader)readers.next();
> System.err.println("Got a reader -- " +
> eader -- " + reader.getFormatName());
> }
> catch (IllegalArgumentException iae)
> {
> System.err.println("Illegal Arguement
> al Arguement Exception...");
> status = false;
> }
> catch (IOException ioe)
> {
> System.err.println("IO Exception...");
> status = false;
> }
> return status;
> }
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net