My company has an EJB that attempts to convert a grayscale TIFF image (which is read into a RenderedImage
) to a PNG image through PNGImageEncoder.encode
.
Today, I learned that it would, under circumstances that I don't know (I was not the author, and I am not present on the test site), throw a division by zero exception. I found it unusual that it was thrown by PNGImageEncoder
. Trying to search for the issue online did not turn in anything useful.
The exception:
java.lang.ArithmeticException: divide by zero
at com.sun.media.jai.codecimpl.PNGImageEncoder.encodePass(PNGImageEncoder.java:367)
at com.sun.media.jai.codecimpl.PNGImageEncoder.writeIDAT(PNGImageEncoder.java:476)
at com.sun.media.jai.codecimpl.PNGImageEncoder.encode(PNGImageEncoder.java:1026)
at com.nameOfMyCompany.SomeProgram.writePNG(SomeProgram.java:555)
Upon further investigation, I suspect that the TIFF images used (which I have no access to) have the bit depth set to 0 for some reason (ImageEncoder code). PNGImageEncoder.encodePass
cannot calculate samplesPerByte
, and the exception is thrown.
My question: Am I right in suspecting the TIFF images to be the reason? What else could cause the above exception?
Your question is yes/no so the answer is yes since the line there shows a division that means there is a division and probably by zero if the error says so.
Beyond that you say "(which is read into a RenderedImage)": is this displayable in java (can you create a jpanel and show this RenderedImage?)? if so then you can use some other mechanism (ImageIO) to convert the Renderable to png (and skip this program that you are using). If not then the long process of TIFF investigation starts.