照片GPS信息添加

这篇博客介绍了如何利用开源库Exiv2在C++中读写照片的EXIF信息,特别是添加GPS信息。通过Qt进行封装,程序实现了读取文件夹中所有照片并根据txt文件的经纬度数据来更新照片的GPS EXIF元数据。
摘要由CSDN通过智能技术生成

数码相机拍照都有EXIF信息,GPS信息就是加在EXIF里的;
Exiv2是一个开源的项目用来读写照片的EXIF信息,附上官网https://www.exiv2.org/
关于Exiv2和EXIF的介绍网上的资料很多,不在多介绍
结合官方的例子(https://www.exiv2.org/doc/examples.html),用Qt对Exiv2进行简单的封装实现添加GPS添加和EXIF信息查询
.h文件

#include <QObject>
#include<QString>
#include"exiv2/exiv2.hpp"
using namespace std;

//经度  纬度  高度
const QString GPS_Longitude="Exif.GPSInfo.GPSLongitude";
const QString GPS_Latitude="Exif.GPSInfo.GPSLatitude";
const QString GPS_Altitude="Exif.GPSInfo.GPSAltitude";

class ImageAnalysis : public QObject
{
   
    Q_OBJECT
public:
    explicit ImageAnalysis(QObject *parent = nullptr);
public:
    //重新设置分析的照片
    void Reset(const QString &imagePath);
    //添加GPS信息
    bool AddExifGPSInfo(const QString &keyStr, const QString &value);
    //设置完后,把数据写入
    bool WriteExifData();
    //查找一个ExifKey避免没有的Key产生段错误  目前没有用
    QString FindExifKey(const QString &key);
private:
    //照片的路径
    QString m_imagePath;
    std::auto_ptr<Exiv2::Image> m_imagePtr;
    Exiv2::ExifData m_ed;
private:
    //度转度分秒
    QStringList DegreeToDDMMSS(const QString& degree);
    QString GetDDMMSS(const QString& degree,int n,bool bEnd=false);
    QString DDMMSSToExivGps(QStringList &strList);//把度分秒转换为exiv 保存的gps字符串格式
    QString AltitudeToExiivGps(const QString &altitude);//把高度转换为exiv 保存的gps字符串格式
};

.cpp文件

#include "imageanalysis.h"
#include<QDebug>
#include<iostream>
#include<QMessageBox>
#include<qmath.h>
using namespace std;

ImageAnalysis::ImageAnalysis(QObject *parent) : QObject(parent),m_imagePath("")
{
   
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值