使用cpp的exiv2库编写将经纬度信息写入图片并可以在windows图片属性中查看经纬度脚本
时间: 2023-05-17 14:02:46 浏览: 113
非常感谢您的提问。以下是使用cpp的exiv2库编写将经纬度信息写入图片并可以在windows图片属性中查看经纬度的脚本示例:
#include <iostream>
#include <exiv2/exiv2.hpp>
int main(int argc, char* argv[]) {
try {
// Open the image file
std::string imagePath = "example.jpg";
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(imagePath);
if (!image.get()) {
std::cerr << "Failed to open image file: " << imagePath << std::endl;
return 1;
}
// Read the image metadata
image->readMetadata();
// Set the GPS coordinates
Exiv2::ExifData& exifData = image->exifData();
exifData["Exif.GPSInfo.GPSLatitude"] = Exiv2::Rational(40, 1);
exifData["Exif.GPSInfo.GPSLatitudeRef"] = "N";
exifData["Exif.GPSInfo.GPSLongitude"] = Exiv2::Rational(120, 1);
exifData["Exif.GPSInfo.GPSLongitudeRef"] = "E";
// Write the updated metadata to the image file
image->setExifData(exifData);
image->writeMetadata();
std::cout << "GPS coordinates written to image file: " << imagePath << std::endl;
return 0;
}
catch (std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
}
希望这个脚本对您有所帮助。如果您有任何其他问题,请随时问我。
阅读全文