xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Fran├žois El Fouly <jean-franc...@elfouly.fr>
Subject Using PNGEncoder and PNGDecoder
Date Wed, 17 Sep 2008 04:39:12 GMT
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: general-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: general-help@xmlgraphics.apache.org


Mime
View raw message