首页 > 其他 > 详细

检核图片文件类型

时间:2020-01-17 14:50:05      阅读:80      评论:0      收藏:0      [点我收藏+]
     /// <summary>
        /// 检核文件类型
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public string getFileType(string strFileName)
        {
            try
            {
                Dictionary<string, string> dicFileType = new Dictionary<string, string>();
                dicFileType.Add("255216", "JPG");
                dicFileType.Add("6677", "BMP");
                dicFileType.Add("13780", "PNG");
                dicFileType.Add("3780", "PDF");
                dicFileType.Add("12392", "RTF");

                System.IO.FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.BinaryReader reader = new System.IO.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();

                return dicFileType[fileClass];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

检核图片文件类型

原文:https://www.cnblogs.com/6B23/p/12205702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!