How to Fetch the Geotag details of the captured image or stored image in Windows phone 8

后端 未结 4 955
说谎
说谎 2021-02-04 13:30

I want to fetch the information from the image regarding the Geolocation as shown in the image below

4条回答
  •  感情败类
    2021-02-04 13:56

    I remember that the PhotoResult you got from the chooser does not have the GPS info. But there's a workaround to get the taken photo with GPS on WP8. According to http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006(v=vs.105).aspx

    On Windows Phone 8, if the user accepts a photo taken with the camera capture task, the photo is automatically saved to the phone’s camera roll.

    So what you have to do is taking the last photo in MediaLibrary instead of using the PhotoResult.

    // For WP8, the taken photo inside a app will be automatically saved.
    // So we take the last picture in MediaLibrary.
    using (MediaLibrary library = new MediaLibrary())
    {
        string filePath = "x.jpg";
        MemoryStream fileStream = new MemoryStream();// MemoryStream does not need to call Close()
        Picture photoFromLibrary = library.Pictures[library.Pictures.Count - 1];// Get last picture
        Stream stream = photoFromLibrary.GetImage();
        stream.CopyTo(fileStream);
        SaveMemoryStream(fileStream, filePath);
    }
    
    private void SaveMemoryStream(MemoryStream ms, string path)
    {
        try
        {
            using (var isolate = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream file = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, isolate))
                {
                    ms.WriteTo(file);
                }
            }
        }
        finally
        {
            IsolatedStorageMutex.ReleaseMutex();
        }
    }
    

    The x.jpg saved in IsolatedStorage will have the GPS info and you can get it out using any library which can handle EXIF data.

提交回复
热议问题