• C# 获取照片拍摄时间


    找了好久才找到这个方法贴出来分享下,这个方法主要是获取照片的拍摄时间^_^

    调用的时候如下;ALLNAME是照片的绝对路径...如果返回值为"N/A"说明照片不存在拍摄时间足够属性没有取到
     string time = GetTakePicDateTime(GetExifProperties(AllName));


    //下面是完整的代码
     public static PropertyItem[] GetExifProperties(string fileName)
            {
                FileStream stream 
    = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                
    //通过指定的数据流来创建Image
                System.Drawing.Image image = System.Drawing.Image.FromStream(stream, truefalse);
                PropertyItem[] r 
    = image.PropertyItems;
                 stream.Close();
                
    return r;
            }

            
    private string GetTakePicDateTime(System.Drawing.Imaging.PropertyItem[] parr)
            {
                Encoding ascii 
    = Encoding.ASCII;
                
    //遍历图像文件元数据,检索所有属性
                foreach (System.Drawing.Imaging.PropertyItem p in parr)
                {
                    
    //如果是PropertyTagDateTime,则返回该属性所对应的值
                    if (p.Id == 0x0132)
                    {
                        
    return ascii.GetString(p.Value);
                    }
                }
                
    //若没有相关的EXIF信息则返回N/A
                return "N/A";
            }
  • 相关阅读:
    oracle的安装与plsql的环境配置
    Working with MSDTC
    soapui-java.lang.Exception Failed to load url
    Oracle 一个owner访问另一个owner的table,不加owner
    Call API relation to TLS 1.2
    Call API HTTP header Authorization: Basic
    VS2008 .csproj cannot be opened.The project type is not supported by this installat
    The changes couldn't be completed.Please reboot your computer and try again.
    Create DB Table View Procedure
    DB Change
  • 原文地址:https://www.cnblogs.com/weiling/p/1569067.html
Copyright © 2020-2023  润新知