确定文件是否为图像

编程入门 行业动态 更新时间:2024-10-21 07:58:13
本文介绍了确定文件是否为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在遍历一个目录并复制所有文件.现在我正在对 ".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

更多推荐

确定文件是否为图像

本文发布于:2023-11-29 17:16:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647065.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!