public static ImageExif ExifInfo(Image img) { System.Drawing.Imaging.PropertyItem[] pt = img.PropertyItems; ImageExif exif = new ImageExif(); for (int i = 0; i < pt.Length; i++) { PropertyItem p = pt[i]; switch (pt[i].Id) { // 设备制造商 20. case 0x010F: exif.Make = System.Text.ASCIIEncoding.ASCII.GetString(pt[i].Value); break; case 0x0110: // 设备型号 25. exif.Model = GetValueOfType2(p.Value); break; case 0x0132: // 拍照时间 30. exif.DateTime = GetValueOfType2(p.Value); break; case 0x829A: // .曝光时间 exif.ExposureTime = GetValueOfType5(p.Value) + " sec"; break; case 0x8827: // ISO 40. exif.ISO = GetValueOfType3(p.Value); break; case 0x010E: // 图像说明info.description exif.ImageTitle = GetValueOfType2(p.Value); break; case 0x920a: //相片的焦距 exif.FocalLength = GetValueOfType5A(p.Value) + " mm"; break; case 0x829D: //相片的光圈值 exif.Aperture = GetValueOfType5A(p.Value); break; case 0x0112: //方向 exif.Orientation = ShortToString(p.Value, 0); break; case 0x011A: exif.XResolution = RationalToSingle(p.Value, 0); break; case 0x011B: exif.YResolution = RationalToSingle(p.Value, 0); break; case 0x0128: exif.ResolutionUnit = RationalToSingle(p.Value, 0); break; case 0x0131: exif.Software = ASCIIToString(p.Value); break; case 0x0002: exif.GPSLatitude = string.Format("{0}°{1}′{2}″", RationalToSingle(p.Value, 0), RationalToSingle(p.Value, 8), RationalToSingle(p.Value, 16)); break; case 0x0004: exif.GPSLongitude = string.Format("{0}°{1}′{2}″", RationalToSingle(p.Value, 0), RationalToSingle(p.Value, 8), RationalToSingle(p.Value, 16)); break; case 0x0006: exif.GPSAltitude = RationalToSingle(p.Value, 0); break; } } return(exif); }
public void GetExifInfo_Tests() { var result = ImageExif.GetExifInfo(imagePath); var re = result; }
private void button1_Click(object sender, EventArgs e) { Image img = Image.FromFile(@"C:\Users\Administrator\Pictures\logo.png"); ImageExif exif = ImageHelper.Exif.GetExifInfo(img); }
public void GetExifDateTime_Tests() { var result = ImageExif.GetExifDateTime(imagePath); Assert.AreEqual(result, ""); }