Java – check whether a file is an image

I am using Jai and creating a file:

PlanarImage img = JAI.create("fileload",myFilename);

If the file exists, I check the line before But how to check the file is BMP is still TIFF or image file?

Does anyone know?

Solution

The image magick project has the function of recognizing images, and there is also a Java wrapper for image magick called jmagick. I think you may need to consider, rather than reinvent the wheel:

http://www.jmagick.org

I have been using image magick, including the "recognition" function from the command line, and have never failed to recognize images once

Back in the days when I absolutely needed this feature, jmagick didn't exist, and I was used to the runtime Exec () ImageMagick's Java recognition command works perfectly

Now jmagick exists, which may no longer be needed (but I haven't tried jmagick yet)

Note that it provides more than just formats, such as:

$ identify tmp3.jpg 
tmp3.jpg JPEG 1680x1050 1680x1050+0+0 DirectClass 8-bit 293.582kb 

$ identify tmp.png
tmp.png PNG 1012x900 1012x900+0+0 DirectClass 8-bit 475.119kb
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>