Error converting (some) tiff to jpeg: Invalid argument to native writeImage
See original GitHub issueWhile converting tiff files to JPEG, we occasionally (rarely) will run into the following error:
Note: The same file will convert properly to PNG format.
javax.imageio.IIOException: Invalid argument to native writeImage
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeOnThread(JPEGImageWriter.java:1067)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:363)
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:173)
at javax.imageio.ImageWriter.write(ImageWriter.java:615)
at javax.imageio.ImageIO.doWrite(ImageIO.java:1622)
at javax.imageio.ImageIO.write(ImageIO.java:1588)
I’m attaching a sample maven project which has sample files and test cases. You should see a failure in the test case com.acme.ConvertTiffToJpegTest#convertProblemTiff
Version Info:
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.8.2</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.8.2</version>
</dependency>
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (Temurin)(build 25.332-b09, mixed mode)
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Unable to conver TIFF to JPG #155 - haraldk/TwelveMonkeys
Hello, I'm trying to convert a TIFF to a JPG and I get this error: SEVERE: Invalid argument to native writeImage javax.imageio.
Read more >Creating a JPEG from a TIFF file fails with imageWrite
Creating a JPEG image from a TIFF file fails with the error: "IIOException: Invalid argument to native writeImage".
Read more >ImageIO not able to write a JPEG file - Stack Overflow
Caused by: javax.imageio.IIOException: Invalid argument to native writeImage at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method) at ...
Read more >204 Error writing tile image: Invalid argument to native writeIm
Hi,. looks similar to ID: 3465530. Happens, if JPEG is created (no problem with PNG). I require JPEG for TwoNav (*.rmap).
Read more >converting jpeg image to tiff - Oracle Communities
Hi all i am trying to convert jpe image to tiff format..i have tried with this code import java.awt.image.BufferedImage; import java.io.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, I’m not sure why this image has an alpha channel. The image was created as part of a test dataset long ago where I used an app to convert a PDF to Tiff. I just happened to notice that it failed like some of the other live data we saw.
Regarding the ImageIO.write result, I tried Open JDK 17 and it does return false instead of failing so it’s definitely something with OpenJDK 8.
For our purposes, I’m fine with just using PNG if the alpha channel is present. We only use JPEG if there is color in the image because the performance was much faster.
Thanks for the link to the JDK9 PNG writer backport. That looks very interesting. I’ll give it a shot.