mfc如何获取图片的gps信息呀?

「已注销」 2019-08-23 10:12:30
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2019-08-24
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903的回复:
什么样的图片贴一个出来看看呢
就是手机拍出来的那种,带地理位置的
zgl7903 2019-08-24
  • 打赏
  • 举报
回复
什么样的图片贴一个出来看看呢
zgl7903 2019-08-24
  • 打赏
  • 举报
回复
凌乱哥 2019-08-24
  • 打赏
  • 举报
回复
引用 4 楼 qq_45366073 的回复:
我这次学的这个好像没有GDI+,只有GDI。。。。。
这个是哪个?那就去学GDI+呗,比GDI强大的多
「已注销」 2019-08-24
  • 打赏
  • 举报
回复
引用 3 楼 凌乱哥的回复:
这个问题我真是知道,因为我之前研究过图片的方向信息。 总的来说,有些设备拍出来的图片会带有“方向、设备、时间、地点、位置”等等信息,这些信息统称为EXIF信息,具体可以百度,然后推荐一个在线查看图片EXIF信息的网站,比如我上传了一张iPhone6拍摄的图片,就可以解析出包含大量的额外信息,包括楼主想知道的GPS信息,如图: 接下来上代码获取,用的是MFC的GDI+相关的图片接口:

	Image* pImg = Image::FromFile(_T("F:\\多媒体素材\\Photos\\IMG_0166.JPG"), FALSE);
	if (pImg) {
		PropertyItem* propertyItem = NULL;
		UINT size = pImg->GetPropertyItemSize(PropertyTagGpsLatitudeRef);
		if (size) {
			propertyItem = (PropertyItem*)malloc(size);
			if (propertyItem) {
				Status stGet = pImg->GetPropertyItem(PropertyTagGpsLatitudeRef, size, propertyItem);
				if ((stGet == Status::Ok) && (propertyItem->value)) {
					char* pValue = (char*)propertyItem->value;//注意这里,不同的属性强转的类型也不同
				}
				delete propertyItem;
				propertyItem = NULL;
			}
		}
		delete pImg;
		pImg = NULL;
	}
其中PropertyTagGpsLatitudeRef在gdiplusimaging.h中有定义,还有很多很多,而楼主需要的GPS相关的就多达31种:

#define PropertyTagGpsVer             0x0000
#define PropertyTagGpsLatitudeRef     0x0001
#define PropertyTagGpsLatitude        0x0002
#define PropertyTagGpsLongitudeRef    0x0003
#define PropertyTagGpsLongitude       0x0004
#define PropertyTagGpsAltitudeRef     0x0005
#define PropertyTagGpsAltitude        0x0006
#define PropertyTagGpsGpsTime         0x0007
#define PropertyTagGpsGpsSatellites   0x0008
#define PropertyTagGpsGpsStatus       0x0009
#define PropertyTagGpsGpsMeasureMode  0x00A
#define PropertyTagGpsGpsDop          0x000B  // Measurement precision
#define PropertyTagGpsSpeedRef        0x000C
#define PropertyTagGpsSpeed           0x000D
#define PropertyTagGpsTrackRef        0x000E
#define PropertyTagGpsTrack           0x000F
#define PropertyTagGpsImgDirRef       0x0010
#define PropertyTagGpsImgDir          0x0011
#define PropertyTagGpsMapDatum        0x0012
#define PropertyTagGpsDestLatRef      0x0013
#define PropertyTagGpsDestLat         0x0014
#define PropertyTagGpsDestLongRef     0x0015
#define PropertyTagGpsDestLong        0x0016
#define PropertyTagGpsDestBearRef     0x0017
#define PropertyTagGpsDestBear        0x0018
#define PropertyTagGpsDestDistRef     0x0019
#define PropertyTagGpsDestDist        0x001A
#define PropertyTagGpsProcessingMethod 0x001B
#define PropertyTagGpsAreaInformation 0x001C
#define PropertyTagGpsDate            0x001D
#define PropertyTagGpsDifferential    0x001E
最后附上PropertyItem的定义以及属性的数据类型的定义:

//---------------------------------------------------------------------------
// Property Item
//---------------------------------------------------------------------------
class PropertyItem
{
public:
    PROPID  id;                 // ID of this property
    ULONG   length;             // Length of the property value, in bytes
    WORD    type;               // Type of the value, as one of TAG_TYPE_XXX
                                // defined above
    VOID*   value;              // property value
};

//---------------------------------------------------------------------------
// Image property types 
//---------------------------------------------------------------------------
#define PropertyTagTypeByte        1
#define PropertyTagTypeASCII       2
#define PropertyTagTypeShort       3
#define PropertyTagTypeLong        4
#define PropertyTagTypeRational    5
#define PropertyTagTypeUndefined   7
#define PropertyTagTypeSLONG       9
#define PropertyTagTypeSRational  10
我这次学的这个好像没有GDI+,只有GDI。。。。。
凌乱哥 2019-08-24
  • 打赏
  • 举报
回复
这个问题我真是知道,因为我之前研究过图片的方向信息。 总的来说,有些设备拍出来的图片会带有“方向、设备、时间、地点、位置”等等信息,这些信息统称为EXIF信息,具体可以百度,然后推荐一个在线查看图片EXIF信息的网站,比如我上传了一张iPhone6拍摄的图片,就可以解析出包含大量的额外信息,包括楼主想知道的GPS信息,如图: 接下来上代码获取,用的是MFC的GDI+相关的图片接口:

	Image* pImg = Image::FromFile(_T("F:\\多媒体素材\\Photos\\IMG_0166.JPG"), FALSE);
	if (pImg) {
		PropertyItem* propertyItem = NULL;
		UINT size = pImg->GetPropertyItemSize(PropertyTagGpsLatitudeRef);
		if (size) {
			propertyItem = (PropertyItem*)malloc(size);
			if (propertyItem) {
				Status stGet = pImg->GetPropertyItem(PropertyTagGpsLatitudeRef, size, propertyItem);
				if ((stGet == Status::Ok) && (propertyItem->value)) {
					char* pValue = (char*)propertyItem->value;//注意这里,不同的属性强转的类型也不同
				}
				delete propertyItem;
				propertyItem = NULL;
			}
		}
		delete pImg;
		pImg = NULL;
	}
其中PropertyTagGpsLatitudeRef在gdiplusimaging.h中有定义,还有很多很多,而楼主需要的GPS相关的就多达31种:

#define PropertyTagGpsVer             0x0000
#define PropertyTagGpsLatitudeRef     0x0001
#define PropertyTagGpsLatitude        0x0002
#define PropertyTagGpsLongitudeRef    0x0003
#define PropertyTagGpsLongitude       0x0004
#define PropertyTagGpsAltitudeRef     0x0005
#define PropertyTagGpsAltitude        0x0006
#define PropertyTagGpsGpsTime         0x0007
#define PropertyTagGpsGpsSatellites   0x0008
#define PropertyTagGpsGpsStatus       0x0009
#define PropertyTagGpsGpsMeasureMode  0x00A
#define PropertyTagGpsGpsDop          0x000B  // Measurement precision
#define PropertyTagGpsSpeedRef        0x000C
#define PropertyTagGpsSpeed           0x000D
#define PropertyTagGpsTrackRef        0x000E
#define PropertyTagGpsTrack           0x000F
#define PropertyTagGpsImgDirRef       0x0010
#define PropertyTagGpsImgDir          0x0011
#define PropertyTagGpsMapDatum        0x0012
#define PropertyTagGpsDestLatRef      0x0013
#define PropertyTagGpsDestLat         0x0014
#define PropertyTagGpsDestLongRef     0x0015
#define PropertyTagGpsDestLong        0x0016
#define PropertyTagGpsDestBearRef     0x0017
#define PropertyTagGpsDestBear        0x0018
#define PropertyTagGpsDestDistRef     0x0019
#define PropertyTagGpsDestDist        0x001A
#define PropertyTagGpsProcessingMethod 0x001B
#define PropertyTagGpsAreaInformation 0x001C
#define PropertyTagGpsDate            0x001D
#define PropertyTagGpsDifferential    0x001E
最后附上PropertyItem的定义以及属性的数据类型的定义:

//---------------------------------------------------------------------------
// Property Item
//---------------------------------------------------------------------------
class PropertyItem
{
public:
    PROPID  id;                 // ID of this property
    ULONG   length;             // Length of the property value, in bytes
    WORD    type;               // Type of the value, as one of TAG_TYPE_XXX
                                // defined above
    VOID*   value;              // property value
};

//---------------------------------------------------------------------------
// Image property types 
//---------------------------------------------------------------------------
#define PropertyTagTypeByte        1
#define PropertyTagTypeASCII       2
#define PropertyTagTypeShort       3
#define PropertyTagTypeLong        4
#define PropertyTagTypeRational    5
#define PropertyTagTypeUndefined   7
#define PropertyTagTypeSLONG       9
#define PropertyTagTypeSRational  10

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧