C # How to obtain the GPS information and latitude and longitude in The Exif information in the photo

Source: Internet
Author: User

 

Ihua forever C # How to obtain the GPS information and latitude and longitude in The Exif information in the photo

 

10 .. Supplement:I hope to provide detailed code. The code I found on the Internet cannot accurately calculate the longitude and latitude information. Supplement:

Additional Section Code

 

# Region
// Merge the image into the video.
Image objImage = Image. FromFile ("E: \ Pictures \ 20080512131.jpg ");
// Obtain all the adequacy (sorted by PropertyId)
Var propertyItems = objImage. PropertyItems. OrderBy (x => x. Id );
// When the regression degree is N (North Region)
Char chrGPSLatitudeRef = 'n ';
// Adjust the economic experience to E (Eastern)
Char chrGPSLongitudeRef = 'E ';
Foreach (PropertyItem objItem in propertyItems)
{
// Only use Id 00000000000000 to 0x001e
If (objItem. Id> = 0x0000 & objItem. Id <= 0x001e)
{
ObjItem. Id = 0x0002;
Switch (objItem. Id)
{
Case 0x0000:
Var query = from tmpb in objItem. Value select tmpb. ToString ();
String sreVersion = string. Join (".", query. ToArray ());
RichTextBox1.Text = sreVersion;
Break;
Case 0x0001:
ChrGPSLatitudeRef = BitConverter. ToChar (objItem. Value, 0 );
Break;
Case 0x0002:
If (objItem. Value. Length = 24)
{
// Degrees (set byte [0] ~ Byte [3] splits into uint, divided by byte [4] ~ Byte [7] uint converted into bytes)
Double d = BitConverter. ToUInt32 (objItem. Value, 0) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 4 );
// Minutes (set byte [8] ~ Byte [11] splits into uint, divided by byte [12] ~ Byte [15] uint converted into bytes)
Double m = BitConverter. ToUInt32 (objItem. Value, 8) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 12 );
// Seconds (set byte [16] ~ Byte [19] equals to uint, divided by byte [20] ~ Byte [23] uint converted into bytes)
Double s = BitConverter. ToUInt32 (objItem. Value, 16) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 20 );
// Calculates the number of degrees. If it is a South region, it must be multiplied by (-1)
Double dblGPSLatitude = (s/60 + m)/60) + d) * (chrGPSLatitudeRef. Equals ('n ')? 1:-1 );
String strLatitude = string. format ("{0: #} deg {1: #} '{2 :#. 00 }\ "{3}", d, m, s, chrGPSLatitudeRef );
}
Break;
Case 0x0003:
// Convert the Value into Char ('E'/'W') through BitConverter ')
// This value is used in the longpolling calculation of the backend vertex.
ChrGPSLongitudeRef = BitConverter. ToChar (objItem. Value, 0 );
Break;
Case 0x0004:
If (objItem. Value. Length = 24)
{
// Degrees (set byte [0] ~ Byte [3] splits into uint, divided by byte [4] ~ Byte [7] uint converted into bytes)
Double d = BitConverter. ToUInt32 (objItem. Value, 0) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 4 );
// Minutes (set byte [8] ~ Byte [11] splits into uint, divided by byte [12] ~ Byte [15] uint converted into bytes)
Double m = BitConverter. ToUInt32 (objItem. Value, 8) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 12 );
// Seconds (set byte [16] ~ Byte [19] equals to uint, divided by byte [20] ~ Byte [23] uint converted into bytes)
Double s = BitConverter. ToUInt32 (objItem. Value, 16) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 20 );
// Calculates the number of degrees. If it is a western economy, it must be multiplied by (-1)
Double dblgpslong1_= (s/60 + m)/60) + d) * (chrGPSLongitudeRef. Equals ('E ')? 1:-1 );
Console. WriteLine ("{0: #} deg {1: #} '{2: #. 00} \" {3} ", d, m, s, chrGPSLongitudeRef );
}
Break;
Case 0x0005:
String strAltitude = BitConverter. ToBoolean (objItem. Value, 0 )? "0": "1 ";
Break;
Case 0x0006:
If (objItem. Value. Length = 8)
{
// Change byte [0] ~ Byte [3] splits into uint, divided by byte [4] ~ Byte [7] uint converted into bytes
Double dblAltitude = BitConverter. ToUInt32 (objItem. Value, 0) * 1.0d/BitConverter. ToUInt32 (objItem. Value, 4 );
}
Break;
}
}
}
# Endregion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.