ファイルアップロードで、カメラメイク、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.