C#でExif情報を読み出すプログラムを書けないか調べたところ、System.Drawing.Image.PropertyItems プロパティを使って画像に格納されたメタデータを取得できることがわかった。
Image.PropertyItems プロパティ (System.Drawing)
http://msdn.microsoft.com/ja-jp/library/system.drawing.image.propertyitems(v=vs.90).aspx
Exif情報をテキストファイルにダンプするサンプルを書いてみた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
string fileName = @"C:\Temp\Exif test\ff_x_e1_001.JPG"; string dumpName = @"C:\Temp\Exif test\ff_x_e1_001.txt"; StreamWriter sw = new StreamWriter(dumpName); Bitmap bitmap = new Bitmap(fileName); foreach (PropertyItem item in bitmap.PropertyItems) { sw.Write("Id: {0:X4}, Len: {1}, Type: {2}, Value: ", item.Id, item.Len, item.Type); switch (item.Type) { case 1: // BYTE: array of bytes for (int i = 0; i < item.Len; i++) sw.Write("{0} ", item.Value[i].ToString("X2")); break; case 2: // ASCII: null-terminated ASCII string sw.Write(Encoding.ASCII.GetString(item.Value)); break; case 3: // SHORT: array of unsigned short (16bit) for (int i = 0; i < item.Len; i += 2) sw.Write("{0} ", BitConverter.ToUInt16(item.Value, i)); break; case 4: // LONG: array of unsigned long (32bit) for (int i = 0; i < item.Len; i += 4) sw.Write("{0} ", BitConverter.ToUInt32(item.Value, i)); break; case 5: // RATIONAL: array of pairs of unsigned long for (int i = 0; i < item.Len; i += 8) sw.Write("{0}/{1} ", BitConverter.ToUInt32(item.Value, i), BitConverter.ToUInt32(item.Value, i + 4)); break; case 7: // UNDEFINED: array of bytes for (int i = 0; i < item.Len; i++) sw.Write("{0} ", item.Value[i].ToString("X2")); break; case 9: // SLONG: array of singed long for (int i = 0; i < item.Len; i += 4) sw.Write("{0} ", BitConverter.ToInt32(item.Value, i)); break; case 10: // SRATIONAL: array of pairs of singed long for (int i = 0; i < item.Len; i += 8) sw.Write("{0}/{1} ", BitConverter.ToInt32(item.Value, i), BitConverter.ToInt32(item.Value, i + 4)); break; } sw.WriteLine(""); } bitmap.Dispose(); sw.Close(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
Id: 010F, Len: 9, Type: 2, Value: FUJIFILM Id: 0110, Len: 5, Type: 2, Value: X-E1 Id: 0112, Len: 2, Type: 3, Value: 1 Id: 011A, Len: 8, Type: 5, Value: 72/1 Id: 011B, Len: 8, Type: 5, Value: 72/1 Id: 0128, Len: 2, Type: 3, Value: 2 Id: 0131, Len: 28, Type: 2, Value: Digital Camera X-E1 Ver1.01 Id: 0132, Len: 20, Type: 2, Value: 2012:09:29 10:16:13 Id: 0213, Len: 2, Type: 3, Value: 2 Id: 8298, Len: 5, Type: 2, Value: Id: 829A, Len: 8, Type: 5, Value: 10/1700 Id: 829D, Len: 8, Type: 5, Value: 400/100 Id: 8822, Len: 2, Type: 3, Value: 3 Id: 8827, Len: 2, Type: 3, Value: 200 Id: 8830, Len: 2, Type: 3, Value: 1 Id: 9000, Len: 4, Type: 7, Value: 30 32 33 30 Id: 9003, Len: 20, Type: 2, Value: 2012:09:29 10:16:13 Id: 9004, Len: 20, Type: 2, Value: 2012:09:29 10:16:13 Id: 9101, Len: 4, Type: 7, Value: 01 02 03 00 Id: 9102, Len: 8, Type: 5, Value: 32/10 Id: 9201, Len: 8, Type: 10, Value: 749/100 Id: 9202, Len: 8, Type: 5, Value: 400/100 Id: 9203, Len: 8, Type: 10, Value: 597/100 Id: 9204, Len: 8, Type: 10, Value: -33/100 Id: 9205, Len: 8, Type: 5, Value: 300/100 Id: 9207, Len: 2, Type: 3, Value: 5 Id: 9208, Len: 2, Type: 3, Value: 0 Id: 9209, Len: 2, Type: 3, Value: 16 Id: 920A, Len: 8, Type: 5, Value: 1800/100 (以下略) |
Exifデータの意味については仕様書を参照。
JEITA / JEITA規格・AV電子機器部門(デジタルカメラ<電子カメラ一般>関係)
http://www.jeita.or.jp/cgi-bin/standard/list.cgi?cateid=1&subcateid=4
Exchangeable image file format for digital still cameras: Exif Version 2.3
http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf