#
/* getExifGPSTagValueByImgProperties : 사진의 Exif GPS Tag 읽어오기 */
public Dictionary<string, object> getExifGPSTagValueByImgProperties(string filePath)
{
String exifFilePath = @filePath;
Dictionary<string, object> result = null;
Image image = null;
try
{
FileStream fs = new FileStream(exifFilePath, FileMode.Open, FileAccess.Read);
image = Image.FromStream(fs);
result = new Dictionary<string, object>();
if (Array.IndexOf<int>(image.PropertyIdList, 1) != -1 &&
Array.IndexOf<int>(image.PropertyIdList, 2) != -1 &&
Array.IndexOf<int>(image.PropertyIdList, 3) != -1 &&
Array.IndexOf<int>(image.PropertyIdList, 4) != -1)
{
string gpsLatitudeRef = BitConverter.ToChar(image.GetPropertyItem(1).Value, 0).ToString();
string latitude = DecodeRational64u(image.GetPropertyItem(2));
string gpsLongitudeRef = BitConverter.ToChar(image.GetPropertyItem(3).Value, 0).ToString();
string longitude = DecodeRational64u(image.GetPropertyItem(4));
result.Add("txtDroneImageLon", longitude);
result.Add("txtDroneImageLat", latitude);
Console.WriteLine("{0}\t{1} {2}, {3} {4}", exifFilePath, gpsLatitudeRef, latitude, gpsLongitudeRef, longitude);
}
image.Dispose();
fs.Close();
}
catch (Exception)
{
return result;
}
return result;
} // end getLonLat()
private static string DecodeRational64u(System.Drawing.Imaging.PropertyItem propertyItem)
{
uint dN = BitConverter.ToUInt32(propertyItem.Value, 0);
uint dD = BitConverter.ToUInt32(propertyItem.Value, 4);
uint mN = BitConverter.ToUInt32(propertyItem.Value, 8);
uint mD = BitConverter.ToUInt32(propertyItem.Value, 12);
uint sN = BitConverter.ToUInt32(propertyItem.Value, 16);
uint sD = BitConverter.ToUInt32(propertyItem.Value, 20);
decimal deg;
decimal min;
decimal sec;
// Found some examples where you could get a zero denominator and no one likes to devide by zero
if (dD > 0) { deg = (decimal)dN / dD; } else { deg = dN; }
if (mD > 0) { min = (decimal)mN / mD; } else { min = mN; }
if (sD > 0) { sec = (decimal)sN / sD; } else { sec = sN; }
//if (sec == 0) return string.Format("{0}° {1:0.###}'", deg, min);
//else return string.Format("{0}° {1:0}' {2:0.#}\"", deg, min, sec);
decimal result;
if (sec == 0) result = deg + (min / 60);
else result = deg + (min / 60) + (sec / 3600);
return Math.Round(result, 8).ToString();
}
'💻 Back-End' 카테고리의 다른 글
Telegram Bot API (0) | 2019.10.01 |
---|---|
[JEUS] Session Timeout 설정 (1) | 2019.02.13 |
[Web] #Servlet #GET #POST (0) | 2018.07.24 |
[ASP.NET][C#] All About Office Interop (Excel) (0) | 2018.05.10 |
[동기 vs 비동기] (0) | 2017.11.16 |