2017-01-08 1 views
1

파일 업로드시 카메라 제작, ISO 속도 등의 Exif 데이터를 가져 오려고합니다. 일부 태그 (아래 참조)를 얻을 수 있지만 Exif 디렉토리에서 항목을 추출하는 것에 대한 지침이 필요합니다. 어떤 제안을하시기 바랍니다.MVC 5 카메라 용 Exif 데이터 만들기

  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()); 
    } 

두 루프는 내가 지저분한 알고 있지만, 일부 출력을 제공합니다

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 

감사합니다. Y.

답변

0

해결되었습니다. 이 블록 :

  ArrayList arrayList = new ArrayList(); 

     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}")); 
      arrayList.Add($"{tag.Name} = {tag.Description}"); 

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

이렇게하면 120 개의 exif 태그가 생성됩니다 (원본으로 사용한 사진의 경우). 샘플 : 화이트 밸런스 모드 = 자동 화이트 밸런스

디지털 줌 비율 = 1

초점 거리까지

35 = 28mm

장면 캡처 유형 = 표준

게인 제어 = 낮은 이득

대비 = 없음

1

처리중인 이미지에 카메라 메이크, ISO 등이있는 경우 메타 데이터 추출기이이를 인쇄합니다. 제공하는 이미지에 이러한 세부 정보가 없어야합니다.

0

답장을 보내 주신 덕분에 지금까지 문제가 해결되었습니다. 스 니펫이 괜찮은 항목 (160 개 항목)을 인쇄하는 동안 항목 설명을 변수 또는 배열에 할당 할 수 없습니다. 코드는 다음과 같습니다.

  // 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()); 
    }