zoukankan      html  css  js  c++  java
  • 判断文件是否是图片

    1. private bool IsPicture(string filePath)//filePath是文件的完整路径  
    2.         { 
    3.             try 
    4.             { 
    5.                 FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); 
    6.                 BinaryReader reader = new BinaryReader(fs); 
    7.                 string fileClass; 
    8.                 byte buffer; 
    9.                 byte[] b=new byte[2]; 
    10.                 buffer = reader.ReadByte(); 
    11.                 b[0] = buffer; 
    12.                 fileClass = buffer.ToString(); 
    13.                 buffer = reader.ReadByte(); 
    14.                 b[1]=buffer; 
    15.                 fileClass += buffer.ToString(); 
    16.  
    17.  
    18.                 reader.Close(); 
    19.                 fs.Close(); 
    20.                 if (fileClass == "255216 ")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar  
    21.                 { 
    22.                     return true
    23.                 } 
    24.                 else 
    25.                 { 
    26.                     return false
    27.                 } 
    28.             } 
    29.             catch 
    30.             { 
    31.                 return false
    32.             } 
    33.         } 
  • 相关阅读:
    Python 第四十九章 css 补充
    Python 第四十八章 css样式
    Python 第四十七章 css介绍
    iOS 流媒体 基本使用 和方法注意
    iOS 展示 gif
    iOS UIImage UIImageView 展示图片 不变形 处理
    UIImageView 获取图片的 宽 高
    iOS tabbar 上面更换任意图
    iOS 屏幕原点坐标 && 导航栏风格的自定义
    iOS NSDateFormatter 不安全线程 处理
  • 原文地址:https://www.cnblogs.com/buaaboyi/p/2762162.html
Copyright © 2011-2022 走看看