Skip to main content

RE: [JAI-IMAGEIO] How to get TIFF Metadata in my app

10 replies [Last post]
Anonymous

How about,

// Get the image metadata.
IIOMetadata imageMetadata = null;
Object imageMetadataPropertyValue = image
.getProperty("JAI.ImageMetadata");
if (imageMetadataPropertyValue !=
java.awt.Image.UndefinedProperty) {
imageMetadataPropertyValue = (IIOMetadata)
imageMetadataPropertyValue;
} else {
System.out.println("Image metadata is null!");
}

I use this to get the metadata from a tiff that I just read from the
"ImageRead" operator which uses ImageIO. Brian posted this before for
extracting metadata from PNG file, and should work with most formats.

Ethan

-----Original Message-----
From: jai-imageio@javadesktop.org [mailto:jai-imageio@javadesktop.org]
Sent: Tuesday, October 24, 2006 10:17 AM
To: interest@jai-imageio.dev.java.net
Subject: [JAI-IMAGEIO] How to get TIFF Metadata in my app

Hi..

I am writing an application which reads TIFF Images by "image =
ImageIO.read(stream);"

So after this I have no access to the TIFFImageMetadata or
TIFFDirectory...In JAI (reading image by "JAI.create("stream",stream)")
I have the TIFFDirectory in the properties of the image but in ImageIO
there is no such function implemented...I just have access to the Image
Metadata in the TIFFImageReader but not outside of this class in my
java-program...

Does anyone have an idea how to get these Image Metadata in my java
program?

Thx in advance.
Cheers Shoddy
[Message sent by forum member 'shortys' (shortys)]

http://forums.java.net/jive/thread.jspa?messageID=166441

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

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

Reply viewing options

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

Yes, it should be format-independent.

Brian

On Tue, 24 Oct 2006, Ethan Killian wrote:

> How about,
>
> // Get the image metadata.
> IIOMetadata imageMetadata = null;
> Object imageMetadataPropertyValue = image
> .getProperty("JAI.ImageMetadata");
> if (imageMetadataPropertyValue !=
> java.awt.Image.UndefinedProperty) {
> imageMetadataPropertyValue = (IIOMetadata)
> imageMetadataPropertyValue;
> } else {
> System.out.println("Image metadata is null!");
> }
>
> I use this to get the metadata from a tiff that I just read from the
> "ImageRead" operator which uses ImageIO. Brian posted this before for
> extracting metadata from PNG file, and should work with most formats.
>
> Ethan
>
> -----Original Message-----
> From: jai-imageio@javadesktop.org [mailto:jai-imageio@javadesktop.org]
> Sent: Tuesday, October 24, 2006 10:17 AM
> To: interest@jai-imageio.dev.java.net
> Subject: [JAI-IMAGEIO] How to get TIFF Metadata in my app
>
> Hi..
>
> I am writing an application which reads TIFF Images by "image =
> ImageIO.read(stream);"
>
> So after this I have no access to the TIFFImageMetadata or
> TIFFDirectory...In JAI (reading image by "JAI.create("stream",stream)")
> I have the TIFFDirectory in the properties of the image but in ImageIO
> there is no such function implemented...I just have access to the Image
> Metadata in the TIFFImageReader but not outside of this class in my
> java-program...
>
> Does anyone have an idea how to get these Image Metadata in my java
> program?
>
> Thx in advance.
> Cheers Shoddy
> [Message sent by forum member 'shortys' (shortys)]
>
> http://forums.java.net/jive/thread.jspa?messageID=166441
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

shortys
Offline
Joined: 2006-08-01

Well, first thx very much!
But the code gives me "Image metadata is null!"
I have no properties in my Image (getPropertyNames gives me null).
I thought about to change the TIFFImageReader.read method so that I construct a new BufferedImage with properties including the TIFFDirectory but something I do wrong.
I thought about this in the TIFFImageReader.read method:
after "this.theImage = getDestinationImage(..)"
I construct a new BufferedImage with properties by:
"this.theImage = new BufferedImage(this.theImage.getColorModel(), this.theImage.getRaster, false, properties);"
(in Hashtable properties I put the TIFFDirectory)
But when I try to read the properties its empty!
Did I something wrong?

Or does anyone have another idea to get the ImageMetadata?

Thx in andvance!
Cheers
Shoddy

Brian Burkhalter

On Tue, 24 Oct 2006, jai-imageio@javadesktop.org wrote:

> Well, first thx very much!
> But the code gives me "Image metadata is null!"
> I have no properties in my Image (getPropertyNames gives me null).
> I thought about to change the TIFFImageReader.read method so that I construct a new BufferedImage with properties including the TIFFDirectory but something I do wrong.
> I thought about this in the TIFFImageReader.read method:
> after "this.theImage = getDestinationImage(..)"
> I construct a new BufferedImage with properties by:
> "this.theImage = new BufferedImage(this.theImage.getColorModel(), this.theImage.getRaster, false, properties);"
> (in Hashtable properties I put the TIFFDirectory)
> But when I try to read the properties its empty!
> Did I something wrong?

I would be curious to learn which javadoc section stated that this would work.

> Or does anyone have another idea to get the ImageMetadata?

http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageReader.html#getImageMetadata(int)

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

shortys
Offline
Joined: 2006-08-01

>I would be curious to learn which javadoc section stated that this would work.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html

^^see first constructor:
public BufferedImage(ColorModel cm,
WritableRaster raster,
boolean isRasterPremultiplied,
Hashtable properties)
Constructs a new BufferedImage with a specified ColorModel and Raster. If the number and types of bands in the SampleModel of the Raster do not match the number and types required by the ColorModel to represent its color and alpha components, a RasterFormatException is thrown. This method can multiply or divide the color Raster data by alpha to match the alphaPremultiplied state in the ColorModel. [b]Properties for this BufferedImage can be established by passing in a Hashtable of String/Object pairs.[/b]

Thx for the suggestion with the ImageReader.getImageMetadata(int)...I will try this ;)

Message was edited by: shortys

Message was edited by: shortys

Brian Burkhalter

Yeah I have that memorized. ;-)

I think you should post the actual code snippet or better yet as a
self-contained test case.

Brian

On Tue, 24 Oct 2006, jai-imageio@javadesktop.org wrote:

>> I would be curious to learn which javadoc section stated >that this would work.
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html
>
> ^^see first constructor:
> public BufferedImage(ColorModel cm,
> WritableRaster raster,
> boolean isRasterPremultiplied,
> Hashtable properties)
> Constructs a new BufferedImage with a specified ColorModel and Raster. If the number and types of bands in the SampleModel of the Raster do not match the number and types required by the ColorModel to represent its color and alpha components, a RasterFormatException is thrown. This method can multiply or divide the color Raster data by alpha to match the alphaPremultiplied state in the ColorModel. Properties for this BufferedImage can be established by passing in a Hashtable of String/Object pairs.
>
> Thx for the suggestion with the ImageReader.getImageMetadata(int)...I will try this ;)
> [Message sent by forum member 'shortys' (shortys)]
>
> http://forums.java.net/jive/thread.jspa?messageID=166526
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

shortys
Offline
Joined: 2006-08-01

@Brian: I think ImageReader.getImageMetadata(int) would be the finest solution, but how to I get the TIFFImageReader instance so that I can call TIFFImageReader.getImageMetadata(int)?

I read the Image from a stream with:
image = ImageIO.read(stream);

but as this leads to a TIFFImageReader.read(int, ImageReadParam) I don't have the instance of the TIFFImageReader.

Thx in advance
Cheers

Brian Burkhalter

nOn Tue, 24 Oct 2006, jai-imageio@javadesktop.org wrote:

> @Brian: I think ImageReader.getImageMetadata(int) would be the fines solution, but how to I get the TIFFImageReader instance so that I can call TIFFImageReader.getImageMetadata(int)?

Please see:

http://java.sun.com/j2se/1.5.0/docs/guide/imageio/spec/apps.fm3.html

Actually reviewing this doc

http://java.sun.com/j2se/1.5.0/docs/guide/imageio/spec/title.fm.html

as a whole would not be a bad idea.

> I read the Image from a stream with:
> image = ImageIO.read(stream);
>
> but as this leads to a TIFFImageReader.read(int, ImageReadParam) I don't have the instance of the TIFFImageReader.

With respect to TIFFImageReader, your code should never refer to any class not
visible in the provided javadoc. Such classes are subject to change without
notice. I don't know that you did that but just in case.

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

shortys
Offline
Joined: 2006-08-01

Ahhhh...now I got it...thx very much!!!

Well, by the way:
Is it intended that the JAI supports spot colors in future?
It's because at the mom I'm trying to extend the JAI ImageIO so that it can handle the spot color channel in TIFF Images created with Adobe Photoshop. That's why I need the ImageMetadata: because the spot color and solidity values are located in the Photoshop Image Resource Block IFD.
(The only problem at the moment is the formula Photoshop uses to mix the spot color channel in RGB channels)

Brian Burkhalter

On Tue, 24 Oct 2006, jai-imageio@javadesktop.org wrote:

> Ahhhh...now I got it...thx very much!!!
>
> Well, by the way:
> Is it intended that the JAI supports spot colors in future?

Not at present. You could file an enhancement request under the jai-core or
jai-imageio-core project as appropriate.

Brian

> It's because at the mom I extend the JAI ImageIO so that it can handle the spot color channel in TIFF Images created with Adobe Photoshop. That's why I need the ImageMetadata: because the spot color and solidity values are located in the Photoshop Image Resource Block IFD.
> (The only problem at the moment is the formula Photoshop uses to mix the spot color channel in RGB channels)
> [Message sent by forum member 'shortys' (shortys)]
>
> http://forums.java.net/jive/thread.jspa?messageID=166559
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

leoben
Offline
Joined: 2006-11-08

Hi,
did you managed to handle the spot color channel in TIFF Images?
It's possible to add it?

regards