Skip to main content

java.lang.ArithmeticException: / by zero issue.

3 replies [Last post]
sassubra
Offline
Joined: 2006-07-04

Hi,

I got the following exception when i tried to create the multi page tiff file.
This error is not consistent for all images. But it is consistent for few files.

code is like this:

file = new File("sample.tif");
RenderedOp op = JAI.create("fileload", file.getAbsolutePath());
ParameterBlock pb1 = new ParameterBlock();
pb1.removeParameters();
pb1.removeSources();
pb1.addSource(op);
pb1.add((op.getWidth() * xratio) / op.getWidth());
pb1.add((op.getHeight() * yratio) / op.getHeight());
pb1.add(0.0F);
pb1.add(0.0F);
pb1.add(new InterpolationNearest());
RenderedOp rp = JAI.create("scale", pb1, null);
BufferedImage image = rp.getAsBufferedImage();

Exception:

Error: One factory fails for the operation "scale"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498)
at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at com.hp.emsi.ftp.MultiTiff.getBufferedImage(MultiTiff.java:140)
at com.hp.emsi.ftp.MultiTiff.createMultiPage(MultiTiff.java:76)
at com.hp.emsi.ftp.MultiTiff.main(MultiTiff.java:244)
Caused by: java.lang.ArithmeticException: / by zero
at com.sun.media.jai.util.Rational.ceil(Rational.java:242)
at javax.media.jai.ScaleOpImage.layoutHelper(ScaleOpImage.java:318)
at javax.media.jai.ScaleOpImage.(ScaleOpImage.java:427)
at com.sun.media.jai.opimage.ScaleNearestBinaryOpImage.(ScaleNearestBinaryOpImage.java:68)
at com.sun.media.jai.opimage.ScaleCRIF.create(ScaleCRIF.java:116)
... 15 more

Please help me to solve this issue.

Thanks,
sassubra

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
power3d
Offline
Joined: 2006-07-17

Have you look up what is in op?
Do a System.out.println(op.getWidth()) for instance.

sassubra
Offline
Joined: 2006-07-04

The op.getWidth() value of the corrupted image was 1248.

power3d
Offline
Joined: 2006-07-17

pb1.add((op.getWidth() * xratio) / op.getWidth());

is the same as having

pb1.add(xratio);

because op.getWidth()/op.getWidth() equals to 1,

so you are just adding to the pb xratio and yratio.