ImageIO.read () returns null

Phenomenon (problem description)

Today the line there was a problem BufferedImage prevImage = ImageIO.read (inputStream) with debugging go find prevImage = null, but the input stream is good, and the input stream corresponding images can be opened, but the return is null ImageIO.read

Resolution process

Later use the Internet to find ImageIO know, the type of pictures that can be read is limited, you can read the picture format: [BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF , gif]
but the file extension is jpg format stands to reason that should support ah, then download the file down onto the notepad ++ View found prefix:. RIFF ?? WEBPVP8 this shows that the actual format of the file format is the file extension webp sometimes not the actual file format.

Finally Solutions

Because my business only support specific file formats, support for reading in ImageIo range of picture formats, therefore, when reading to null, prompting the user to directly upload pictures to malformed.

Note:
ImageIO.getReaderFileSuffixes () return value: [JPG, BMP, GIF, PNG, WBMP, jpeg]
ImageIO.getReaderFileSuffixes () return value: [JPG, jpg, bmp, BMP, gif, GIF, WBMP, png, PNG, wbmp, jpeg, JPEG]


Guess you like

Origin www.cnblogs.com/tanyucong/p/11057332.html