M
Marian Schedenig
Hi!
I've posted the same question on the imageio-interest mailing list, but
since that seem pretty much defunct, and our client needs a quick solution
to this problem, I'm trying my luck here as well.
I'm trying to change the DPI settings of an image (png, jpg or tiff -
using the jar from JAI for tiff decoding). I'm doing this by getting the
metadata, changing the entries in the DOM tree, and re-setting it to the
metadata. However, I don't get the expected results, so I reduced my
code to the basic part which fails, and apparently I'm having problems
with getAsTree and setFromTree. Basically, what I'm doing now is this:
// ImageReader reader = something;
IIOMetadata metaData = reader.getImageMetadata(reader.getMinIndex());
// output the old metadata to System.out (contains correct values)
Node root = metaData.getAsTree("javax_imageio_1.0"); // (still contains
correct values)
metaData.setFromTree("javax_imageio_1.0", root); // (root contains
correct values)
// output the new metadata to System.out (this has the wrong values)
For all three formats (png, jpg, tiff), I get different results.in the
Dimension nodes. The most problematic is JPEG, which can't seem to read
the node's values at all. PNG changes my pixel size values. Only TIFF
seems to keep the correct values.
Here are the contents of the Dimension nodes for the various formats:
JPEG before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="normal"/>
<HorizontalPixelSize value="0.35277778"/>
<VerticalPixelSize value="0.35277778"/>
</Dimension>
JPEG after:
<Dimension>
<PixelAspectRatio value="NaN"/>
<ImageOrientation value="normal"/>
<HorizontalPixelSize value="Infinity"/>
<VerticalPixelSize value="Infinity"/>
</Dimension>
PNG before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="Normal"/>
<HorizontalPixelSize value="0.35273367"/>
<VerticalPixelSize value="0.35273367"/>
</Dimension>
PNG after:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="Normal"/>
<HorizontalPixelSize value="2.8328612"/>
<VerticalPixelSize value="2.8328612"/>
</Dimension>
TIFF before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<HorizontalPixelSize value="0.35277778"/>
<VerticalPixelSize value="0.35277778"/>
<ImageOrientation value="Normal"/>
</Dimension>
TIFF after:
<Dimension>
<PixelAspectRatio value="1.0"/>
<HorizontalPixelSize value="0.3527785"/>
<VerticalPixelSize value="0.3527785"/>
<ImageOrientation value="Normal"/>
</Dimension>
Any hints on what I'm doing wrong?
Thx,
Marian.
I've posted the same question on the imageio-interest mailing list, but
since that seem pretty much defunct, and our client needs a quick solution
to this problem, I'm trying my luck here as well.
I'm trying to change the DPI settings of an image (png, jpg or tiff -
using the jar from JAI for tiff decoding). I'm doing this by getting the
metadata, changing the entries in the DOM tree, and re-setting it to the
metadata. However, I don't get the expected results, so I reduced my
code to the basic part which fails, and apparently I'm having problems
with getAsTree and setFromTree. Basically, what I'm doing now is this:
// ImageReader reader = something;
IIOMetadata metaData = reader.getImageMetadata(reader.getMinIndex());
// output the old metadata to System.out (contains correct values)
Node root = metaData.getAsTree("javax_imageio_1.0"); // (still contains
correct values)
metaData.setFromTree("javax_imageio_1.0", root); // (root contains
correct values)
// output the new metadata to System.out (this has the wrong values)
For all three formats (png, jpg, tiff), I get different results.in the
Dimension nodes. The most problematic is JPEG, which can't seem to read
the node's values at all. PNG changes my pixel size values. Only TIFF
seems to keep the correct values.
Here are the contents of the Dimension nodes for the various formats:
JPEG before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="normal"/>
<HorizontalPixelSize value="0.35277778"/>
<VerticalPixelSize value="0.35277778"/>
</Dimension>
JPEG after:
<Dimension>
<PixelAspectRatio value="NaN"/>
<ImageOrientation value="normal"/>
<HorizontalPixelSize value="Infinity"/>
<VerticalPixelSize value="Infinity"/>
</Dimension>
PNG before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="Normal"/>
<HorizontalPixelSize value="0.35273367"/>
<VerticalPixelSize value="0.35273367"/>
</Dimension>
PNG after:
<Dimension>
<PixelAspectRatio value="1.0"/>
<ImageOrientation value="Normal"/>
<HorizontalPixelSize value="2.8328612"/>
<VerticalPixelSize value="2.8328612"/>
</Dimension>
TIFF before:
<Dimension>
<PixelAspectRatio value="1.0"/>
<HorizontalPixelSize value="0.35277778"/>
<VerticalPixelSize value="0.35277778"/>
<ImageOrientation value="Normal"/>
</Dimension>
TIFF after:
<Dimension>
<PixelAspectRatio value="1.0"/>
<HorizontalPixelSize value="0.3527785"/>
<VerticalPixelSize value="0.3527785"/>
<ImageOrientation value="Normal"/>
</Dimension>
Any hints on what I'm doing wrong?
Thx,
Marian.