Convert TIF / TIFF to JPG: Bad endianness tag

I am trying to convert TIF / TIFF images to JPG, which works fine, but for multiple TIF images I get the IllegalArgumentException: Bad endianness sign (not 0x4949 or 0x4d4d).

An exception:

java.io.IOException: Bad endianness tag (not 0x4949 or 0x4d4d). at com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76) at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:98) at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:103) at com.sun.media.jai.codec.ImageDecoderImpl.decodeAsRenderedImage(ImageDecoderImpl.java:140) at com.pkg.jae.utils.GenericImageUtils.convertTiffToJpg(GenericImageUtils.java:35) at com.pkg.jae.utils.GenericImageUtils.main(GenericImageUtils.java:92) Caused by: java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d). at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:595) at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:96) ... 4 more 

Code Function:

 public static void convertTiffToJpg(String strTiffUrl,String strJpgFileDestinationUrl) throws Exception { try { FileSeekableStream obj_FileSeekableStream = new FileSeekableStream(new File(strTiffUrl)); ImageDecoder obj_ImageDecoder = ImageCodec.createImageDecoder(EXT_TIFFX, obj_FileSeekableStream, null); RenderedImage obj_RenderedImage = obj_ImageDecoder.decodeAsRenderedImage(); JAI.create("filestore", obj_RenderedImage,strJpgFileDestinationUrl, EXT_JEPGX); obj_RenderedImage = null; obj_ImageDecoder = null; obj_FileSeekableStream.close(); } catch (Exception ex) { throw ex; } } 

If someone knows the problem and can help with this.

+6
source share
3 answers

As pointed out in the bitbank comment, this means that you transfer the JPEG file to it when it expects to receive the TIFF file.

0
source

Amazing this jai

 RenderedOp renderer = JAI.create("fileload", filename); BufferedImage bi = renderer.getAsBufferedImage(); 

It doesn’t have the same failure and just works regardless of the type of image. Do not use this particular method (traversing in the file name), although see Is closing JAI files too early?

0
source

I had this problem and it turned out to be a foreground problem. Yes, I tried to download the wrong file type, but I expected the correct processing and a competent pop-up message. Instead, I received an error message.

In my case, I used extjs and I had a crash function:

 failure: function (a) { ...some message alert... } 

instead:

 failure: function (f, a) { ...some message alert... } 

and it threw this exception, instead of displaying my message.

0
source

Source: https://habr.com/ru/post/972751/


All Articles