I am creating an application that for some reasons shall only accept PNG images.
How can I check if an image is really a PNG image? Currently I am using the JavaFX 2 Image class to load the image.
Thanks for any hint!
如果你不信任文件名,一个简单的检查是读取前8个字节(使用FileInputStream
),并检查它们是否对应于PNG签名(相关: https : //stackoverflow.com/a/10555053/277304 )
I do this currently in my own application by confirming the file's Mime Type before I process it. There are several SO threads suggesting how to obtain Mime Types in Java.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.