2017-01-08 1 views
1

Ich versuche, Exif Daten für Kamera machen, ISO-Geschwindigkeit usw. in einem Datei-Upload. Ich kann einige Tags erhalten (siehe unten), benötige jedoch eine Anleitung zum Extrahieren von Elementen aus den Exif-Verzeichnissen. Irgendwelche Vorschläge bitte.MVC 5 Get Exif Daten für Kamera machen

  IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(strFileName); 
     foreach (var directory in directories) 
      foreach (var tag in directory.Tags) 
       System.Diagnostics.Debug.WriteLine(string.Format("Directory " + $"{directory.Name} - {tag.Name} = {tag.Description}")); 

     var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault(); 
     var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTime); 
     System.Diagnostics.Debug.WriteLine(string.Format("dateTime " + dateTime)); 

     // 
     Image img = Image.FromFile(strFileName); 
     ImageFormat format = img.RawFormat; 
     System.Diagnostics.Debug.WriteLine("Image Type : " + format.ToString()); 
     System.Diagnostics.Debug.WriteLine("Image width : " + img.Width); 
     System.Diagnostics.Debug.WriteLine("Image height : " + img.Height); 
     System.Diagnostics.Debug.WriteLine("Image resolution : " + (img.VerticalResolution * img.HorizontalResolution)); 
     System.Diagnostics.Debug.WriteLine("Image Pixel depth : " + Image.GetPixelFormatSize(img.PixelFormat)); 


     PropertyItem[] propItems = img.PropertyItems; 
     int count = 0; 
     ArrayList arrayList = new ArrayList(); 
     foreach (PropertyItem item in propItems) 
     { 
      arrayList.Add("Property Item " + count.ToString()); 
      arrayList.Add("iD: 0x" + item.Id.ToString("x")); 
      System.Diagnostics.Debug.WriteLine("PropertyItem item in propItems: " + item.Id.ToString("Name")); 
      count++; 
     } 

     ASCIIEncoding encodings = new ASCIIEncoding(); 
     try 
     { 
      string make = encodings.GetString(propItems[1].Value); 
      arrayList.Add("The equipment make is " + make.ToString() + "."); 
     } 
     catch 
     { 
      arrayList.Add("no Meta Data Found"); 
     } 

     ViewBag.listFromArray = arrayList; 
     return View(await db.ReadExifs.ToListAsync()); 
    } 

Zwei Schleifen Ich weiß, chaotisch, aber gibt eine Ausgabe:

Directory JPEG - Compression Type = Baseline 
Directory JPEG - Data Precision = 8 bits 
Directory JPEG - Image Height = 376 pixels 
Directory JPEG - Image Width = 596 pixels 
Directory JPEG - Number of Components = 3 
Directory JPEG - Component 1 = Y component: Quantization table 0, Sampling factors 2 horiz/2 vert 
Directory JPEG - Component 2 = Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert 
Directory JPEG - Component 3 = Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert 
Directory JFIF - Version = 1.1 
Directory JFIF - Resolution Units = inch 
Directory JFIF - X Resolution = 120 dots 
Directory JFIF - Y Resolution = 120 dots 
Directory JFIF - Thumbnail Width Pixels = 0 
Directory JFIF - Thumbnail Height Pixels = 0 
Directory File - File Name = FakeFoto03_large.Jpg 
Directory File - File Size = 66574 bytes 
Directory File - File Modified Date = Tue Jan 03 00:02:00 +00:00 2017 
Image Type : [ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e] 
Image width : 596 
Image height : 376 
Image resolution : 14400 
Image Pixel depth : 24 

Dank. Y.

Antwort

0

gelöst. Dieser Block:

Dies erzeugt (im Falle des als Quelle verwendeten Fotos) 120 Exif-Tags. Beispiel: Weißabgleich-Modus = Automatischer Weißabgleich

Verhältnis Digitalzoom = 1

Brennweite 35 = 28 mm

Szenenaufnahmetyp = Standard

Gain Control = Low Gain bis

Kontrast = Keine

1

Wenn das Bild, das Sie bearbeiten, Kamera, ISO und so weiter erstellt, wird der Metadaten-Extraktor es ausdrucken. Das Bild, das Sie bereitstellen, darf diese Details nicht enthalten.

0

Dank Drew für die Antwort, funktioniert jetzt gut, bis zu einem gewissen Punkt. Während der Ausschnitt ausgedruckt wird (160 Elemente), kann ich die Elementbeschreibung nicht einer Variablen oder einem Array zuweisen. Hier ist der Code:

  // start exif ############################### 
     var strFileName = Server.MapPath("~/uploads/" + fname + "_large" + extension); 
     System.Diagnostics.Debug.WriteLine(">>> ReadExifsController, fname: " + fname); 

     if (System.IO.File.Exists(strFileName)) 
     { 
      System.Diagnostics.Debug.WriteLine(">>> ReadExifsController File exists."); 
     } 

     ArrayList arrayList = new ArrayList(); 
     arrayList.Add("ArrayList start"); 

     IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(strFileName); 

foreach (var directory in directories) 
      foreach (var tag in directory.Tags) 
       System.Diagnostics.Debug.WriteLine(string.Format("Directory " + $"{directory.Name} - {tag.Name} = {tag.Description}")); 
     count++; 

     ViewBag.listFromArray = arrayList; 
     return View(await db.ReadExifs.ToListAsync()); 
    }