c#判定文件是否为图片。
- private bool IsPicture(string filePath)
- {
- try
- {
- FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
- BinaryReader reader = new BinaryReader(fs);
- string fileClass;
- byte buffer;
- byte[] b=new byte[2];
- buffer = reader.ReadByte();
- b[0] = buffer;
- fileClass = buffer.ToString();
- buffer = reader.ReadByte();
- b[1]=buffer;
- fileClass += buffer.ToString();
-
-
- reader.Close();
- fs.Close();
- if (fileClass == "255216 ")
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch
- {
- return false;
- }
- }
posted @
2012-11-09 10:40
go on coding
阅读(
1568)
评论()
编辑
收藏
举报