2014-01-31 34 views
0

我有一個應用程序,它顯示遠程存儲在Twitter,Instagram和Flickr服務器上的圖像。我想要的是使用ExifLib來提取Exif信息(主要是GPS數據)並顯示圖像細節。在遠程圖像上使用ExifLib

這是我到目前爲止有:

string metaData = string.Empty; 
string tagValue = string.Empty; 

try 
{ 
    using (var wc = new WebClient()) 
    { 
     byte[] imageBytes = wc.DownloadData(imgUrl); 

     using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) 
     { 
      using (ExifReader reader = new ExifReader(ms)) 
      { 
       if (reader.GetTagValue<string>(ExifTags.GPSAltitude, out tagValue)) 
        Log.Debug("GPSAltitude: " + tagValue); 

       if (reader.GetTagValue<string>(ExifTags.DateTimeDigitized, out tagValue)) 
        Log.Debug("DateTimeDigitized: " + tagValue); 

       if (reader.GetTagValue<string>(ExifTags.DateTimeOriginal, out tagValue)) 
        Log.Debug("DateTimeOriginal: " + tagValue); 

       if (reader.GetTagValue<string>(ExifTags.GPSLatitude, out tagValue)) 
        Log.Debug("GPSLatitude: " + tagValue); 

       if (reader.GetTagValue<string>(ExifTags.GPSLongitude, out tagValue)) 
        Log.Debug("GPSLongitude: " + tagValue); 

      } 
     } 
    } 
} 
catch (Exception ex) 
{ 
    Log.Exception("A problem occurred while fetching Exif data.", ex); 
} 

但是,每IMAGEURL是經歷似乎不能讓過去與圖像的MemoryStream的實例化ExifReader;它總是碰到Exception並且表明ExifLib找不到Exif數據,即使當我選擇明確具有Exif數據的an image from Flickr時也是如此。

我在上面的代碼中做錯了什麼,或者ExifLib不能在遠程圖像上工作?

回答

1

您是否嘗試過檢查imageBytes是否實際上包含有效數據? 將它保存到一個文件中,並查看是否從實際文件重複您的功能會改變任何內容。 也許下載甚至沒有成功,你在try..catch有很多活動。

作爲解決方法,首先將數據保存在服務器上的臨時文件中並使用它。我知道你想避免這種情況,但更好的工作比沒有。並將中間結果記錄在服務器上,以便區分和調試許多可能的缺陷(如錯誤的URL或Flickr不希望您每分鐘超過一定的下載量)。