读取图像文件元数据

时间:2013-05-23 11:28:12

标签: c# php javascript asp.net image

我想上传图片文件,然后提取其基本信息(作者,尺寸,创建日期,修改日期等)并将其显示给用户。我怎么能这样做。

asp.net c#代码中对此问题的解决方案或引用会很有帮助。但javascript或php也可以。

4 个答案:

答案 0 :(得分:1)

检查Link。基于Win-OS版本,您将获得更多关于GetDetailsOf()及其文件属性的清关。

如果您想使用C#代码,请使用以下代码获取元数据:

List<string> arrHeaders = new List<string>();

 Shell shell = new ShellClass();
 Folder rFolder = shell.NameSpace(_rootPath);
 FolderItem rFiles = rFolder.ParseName(filename);

 for (int i = 0; i < short.MaxValue; i++)
 {
      string value = rFolder.GetDetailsOf(rFiles, i).Trim();
      arrHeaders.Add(value);
 }

答案 1 :(得分:0)

Bitmap image = new Bitmap(fileName);
PropertyItem[] propItems = image.PropertyItems;

foreach (PropertyItem item in propItems)
{
  Console.WriteLine("iD: 0x" + item.Id.ToString("x"));
}

MSDN Reference

C# Tutorial Reference

答案 2 :(得分:0)

可以在这里找到C#解决方案: Link1 Link2

答案 3 :(得分:-1)

试试这个......

    private string doUpload()
    {
        // Initialize variables
        string sSavePath;

        sSavePath = "images/";

        // Check file size (mustn’t be 0)
        HttpPostedFile myFile = FileUpload1.PostedFile;
        int nFileLen = myFile.ContentLength;
        if (nFileLen == 0)
        {
            //**************
            //lblOutput.Text = "No file was uploaded.";
            return null;
        }

        // Check file extension (must be JPG)
        if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
        {
            //**************
            //lblOutput.Text = "The file must have an extension of JPG";
            return null;
        }

        // Read file into a data stream
        byte[] myData = new Byte[nFileLen];
        myFile.InputStream.Read(myData, 0, nFileLen);

        // Make sure a duplicate file doesn’t exist.  If it does, keep on appending an 
        // incremental numeric until it is unique
        string sFilename = System.IO.Path.GetFileName(myFile.FileName);
        int file_append = 0;
        while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
        {
            file_append++;
            sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
                             + file_append.ToString() + ".jpg";
        }

        // Save the stream to disk
        System.IO.FileStream newFile
                = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename),
                                           System.IO.FileMode.Create);
        newFile.Write(myData, 0, myData.Length);
        newFile.Close();

        return sFilename;
    }