如何在Windows phone 8中获取拍摄图像或存储图像的地理标记详细信息 [英] How to Fetch the Geotag details of the captured image or stored image in Windows phone 8

查看:101
本文介绍了如何在Windows phone 8中获取拍摄图像或存储图像的地理标记详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图片中获取关于地理定位的信息,如下图所示

//i.stack.imgur.com/ZiUMd.pngalt =

  void cam_Completed( (e.TaskResult == TaskResult.OK)
{

Image cameraImage = new Image();
BitmapImage bImage = new BitmapImage();

bImage.SetSource(e.ChosenPhoto);
cameraImage.Source = bImage;

e.ChosenPhoto.Position = 0;

ExifReader reader = new ExifReader(e.ChosenPhoto);
double gpsLat,gpsLng;

reader.GetTagValue< double>(ExifTags.GPSLatitude,
out gpsLat))

reader.GetTagValue< double>(ExifTags.GPSLongitude,
out gpsLng))


MessageBox.Show(gpsLat.ToString()++ gpsLng.ToString());


$ b $ / code $ / pre

以便我们可以检测出位置图像被拍摄。请帮助找到这些属性。

解决方案

您需要阅读 EXIF 来自图像的数据。

您可以使用类似这样的库

  //实例化阅读器
ExifReader阅读器=新的ExifReader(@..路径到您的图像\ ... jpg);

//使用ExifTags枚举提取标记数据
double gpsLat,gpsLng;
if(reader.GetTagValue< double>(ExifTags.GPSLatitude,
out gpsLat))
{
//根据提取的信息做任何事情
// ...
}
if(reader.GetTagValue< double>(ExifTags.GPSLongitude,
out gpsLng))
{
//做任何必需的提取的信息
// ...
}

更新。 代码改为使用 MemoryStream

  void cam_Completed如果(e.TaskResult == TaskResult.OK)
{
using(MemoryStream memo = new MemoryStream())
{
e.ChosenPhoto.CopyTo(备忘录);
memo.Position = 0;
using(ExifReader reader = new ExifReader(memo))
{
double [] latitudeComponents;
reader.GetTagValue(ExifTags.GPSLatitude,out latitudeComponents);

double [] longitudeComponents;
reader.GetTagValue(ExifTags.GPSLongitude,out longitudeComponents);

// Lat / long存储为D°M'S数组,所以您需要重建它们的值,如下所示:
var latitude = latitudeComponents [0] + latitudeComponents [1] / 60 + latitudeComponents [2] / 3600;
var longitude = longitudeComponents [0] + longitudeComponents [1] / 60 + longitudeComponents [2] / 3600;

//经度和纬度现在应该正确设置...
}
}
}
}


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

 void cam_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {

                Image cameraImage = new Image();
                BitmapImage bImage = new BitmapImage();

                bImage.SetSource(e.ChosenPhoto);
                cameraImage.Source = bImage;

                e.ChosenPhoto.Position = 0;

                ExifReader reader = new ExifReader(e.ChosenPhoto);
                double gpsLat, gpsLng;

                reader.GetTagValue<double>(ExifTags.GPSLatitude,
                                                    out gpsLat))

                reader.GetTagValue<double>(ExifTags.GPSLongitude,
                                                    out gpsLng))


                MessageBox.Show(gpsLat.ToString() + "" + gpsLng.ToString());   

            }
        }

so that we can detect location where the image was taken. Please help to find the these property.

解决方案

You will need to read the EXIF data from the image.

You can use a library such as this

// Instantiate the reader
ExifReader reader = new ExifReader(@"..path to your image\...jpg");

// Extract the tag data using the ExifTags enumeration
double gpsLat, gpsLng;
if (reader.GetTagValue<double>(ExifTags.GPSLatitude, 
                                    out gpsLat))
{
    // Do whatever is required with the extracted information
    //...
}
if (reader.GetTagValue<double>(ExifTags.GPSLongitude, 
                                    out gpsLng))
{
    // Do whatever is required with the extracted information
    //...
}

UPDATE. Code changed to use MemoryStream

    void cam_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            using (MemoryStream memo = new MemoryStream())
            {
                e.ChosenPhoto.CopyTo(memo);
                memo.Position = 0;
                using (ExifReader reader = new ExifReader(memo))
                {
                    double[] latitudeComponents;
                    reader.GetTagValue(ExifTags.GPSLatitude, out latitudeComponents);

                    double[] longitudeComponents;
                    reader.GetTagValue(ExifTags.GPSLongitude, out longitudeComponents);

                    // Lat/long are stored as D°M'S" arrays, so you will need to reconstruct their values as below:
                    var latitude = latitudeComponents[0] + latitudeComponents[1] / 60 + latitudeComponents[2] / 3600;
                    var longitude = longitudeComponents[0] + longitudeComponents[1] / 60 + longitudeComponents[2] / 3600;

                    // latitude and longitude should now be set correctly...
                }
            }
        }
    }

这篇关于如何在Windows phone 8中获取拍摄图像或存储图像的地理标记详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆