本文介绍了确定文件是否为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在遍历一个目录并复制所有文件.现在我正在对 ".jpg" 或 ".png" 等进行 string.EndsWith 检查..
I am looping through a directory and copying all files. Right now I am doing string.EndsWith checks for ".jpg" or ".png", etc . .
是否有更优雅的方法来确定文件是否为图像(任何图像类型)而无需像上面那样进行 hacky 检查?
Is there any more elegant way of determining if a file is an image (any image type) without the hacky check like above?
推荐答案检查文件中的 已知标题.(此答案中也提到了来自链接的信息)
Check the file for a known header. (Info from link also mentioned in this answer)
PNG 文件的前八个字节始终包含以下(十进制)值:137 80 78 71 13 10 26 10
The first eight bytes of a PNG file always contain the following (decimal) values: 137 80 78 71 13 10 26 10
更多推荐
确定文件是否为图像
发布评论