1

I am trying to generate PNG with the following ancillary chunks (header from a reference image) enter image description here

The ancillary chunks in the reference image probably came from GIMP processing.

Whereas the Image I generate with Java AWT does not have those ancillary chunks.
Here is the header of the PNG I am generating. Please note the critical chunks are identical.

enter image description here

Here is the code fragment

{
        :

        // The color map contains the colors black and white
        byte[] cMap = {0, 0, 0, (byte)255, (byte)255, (byte)255};
        // Create an IndexColorModel setting white as the transparent color
        IndexColorModel monochrome = new IndexColorModel(8, 2, cMap, 0, false, 0);
        BufferedImage img = new BufferedImage(width_img, height_img,
                  BufferedImage.TYPE_BYTE_INDEXED,monochrome);
        Graphics2D g2d = img.createGraphics();

        :           

        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, width_img, height_img);

        Font font = new Font("Arial Bold", Font.PLAIN, 48);
        g2d.setFont(font);
        FontMetrics fm = g2d.getFontMetrics();
        g2d.setColor(Color.BLACK);
        :
        :

        g2d.dispose();

        imgName = ".\\Panel"+width_img+"x"+height_img+".png";
        ImageIO.write(img, "png", new File(imgName));
       :
}

How do I add chunks (pHYs, tIME) using Java AWT?

Any pointers will be helpful too- please let me know.

Thank you

abRao
  • 2,787
  • 1
  • 25
  • 37

1 Answers1

0

I concluded that AWT does not support - this questions identifies couple of ways to add chunks How can I save a PNG with a tEXt or iTXt chunk from Java?

Here is what I propose to do -

Use AWT / Graphics 2D to generate the .PNG

Read PNG, refer to the link for details on how to do it

Add the Chunks you want to add

Write it(them) back to the .PNG

Community
  • 1
  • 1
abRao
  • 2,787
  • 1
  • 25
  • 37