Exiv2 —— 删除图片Exif信息(附源码)

效果Exiv2 —— 删除图片Exif信息(附源码)_第1张图片

源码
#include 
#include 
#include 

#include "exiv2/exiv2.hpp"

int main2()
{
	const char imagePath[] = "./test.jpeg";
	Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(imagePath);
	assert(image.get() != 0);
	image->readMetadata();

	Exiv2::ExifData &exifData = image->exifData();
	if (exifData.empty()) { return -1; }

	// *************************************************************************
	// 删除exif信息
	// 从Exif数据容器中删除元数据
	// 删除迭代器位置的元数据
	Exiv2::ExifKey key = Exiv2::ExifKey("Exif.GPSInfo.GPSLongitude");
	Exiv2::ExifData::iterator pos = exifData.findKey(key);
	if (pos != exifData.end())
	{
		exifData.erase(pos);
		std::cout << "Deleted key \"" << key << "\"\n";
	}
	else { std::cout << "Key not found"; }
	// *************************************************************************
	image->setExifData(exifData);
	image->writeMetadata();

	system("pause");
	return 0;
}

关注

笔者 - jxd

你可能感兴趣的:(Exiv2,c++,exif,jpeg,exiv2)