Since we use and embed xmlgraphics-commons for the sake of FOP anyway, I tried to use the PNG encoding / decoding classes in another context of our application (thus, not at all related to FOP or Batik). In two different places at least we need to write or process (read - process - write) PNG images with their PHYS metadata. Since the documentation on using xmlgraphics-commons in general is rather scarce, I tried to figure out myself how to use these classes by reading the code and tried this.

           PNGDecodeParam decodeParam = new PNGDecodeParam();
           decodeParam.setGenerateEncodeParam(true);

PNGImageDecoder decoder = new PNGImageDecoder(new FileInputStream(sourceFile), decodeParam);
           RenderedImage srcImage = decoder.decodeAsRenderedImage();
// Some irrelevant code removed here

BufferedImage dstImage = new BufferedImage(srcImage.getWidth(), srcImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);

           // Some processing here...


           PNGEncodeParam encodeParam = decodeParam.getEncodeParam();
System.out.println("Physical dimensions set ?" + encodeParam.isPhysicalDimensionSet()); System.out.println("Physical dimensions:" + encodeParam.getPhysicalDimension()[0]); PNGImageEncoder encoder = new PNGImageEncoder(new FileOutputStream(destinationFile), encodeParam);
           encoder.encode(dstImage);

Hoping this would propagate the PNG metadata (among which ICCProfile and physical dimensions) from source to destination. Well the image processing code works well and the output file is properly encoded, but without any metadata.
What did I miss in the process ?

Thanks for helping !

Jean-Francois






---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to