Exiv2库的使用(C++)
1 #include <iostream> 2 #include <exiv2/exiv2.hpp> 3 #pragma cment(lib,"libexiv2.lib") 4 #pragma cment(lib,"xmpsdk.lib") 5 #pragma cment(lib,"libexpat.lib") 6 #pragma cment(lib,"zlib1.lib") 7 8 //查找一个ExifKey避免没有的Key产生段错误 9 std::string FindExifKey(Exiv2::ExifData &ed, std::string key) 15 return pos>value().toString(); 16 } 17 18 int main(int argc, char *argv[]) 24 25 //判断文件是否有效 26 if (!Exiv2::fileExists(argv[1], true)) 30 31 //获取文件大小 32 FILE *FP = fopen(argv[1], "rb"); 33 fseek(FP, 0, SEEK_END); //定位到文件末 34 int FileSize = ftell(FP); //文件长度 35 fclose(FP); 36 37 Exiv2::Image::AutoPtr &image = Exiv2::ImageFactory::open(argv[1]); 38 if (image.get() == 0) 39 43 44 //读取照片的exif信息 45 image>readMetadata(); 46 Exiv2::ExifData ed = image>exifData();//得到exif信息 47 48 if (ed.empty()) 49 53 54 std::cout << "文件名称 :" << argv[1] << std::endl; 55 std::cout << "文件大小 :" << FileSize << std::endl; 56 std::cout << "版权 :" << FindExifKey(ed, "Exif.Imageopyright") << std::endl; 57 std::cout << "创作人 :" << FindExifKey(ed, "Exif.Image.Artist") << std::endl; 58 std::cout << "相机品牌 :" << FindExifKey(ed, "Exif.Image.Make") << std::endl; 59 std::cout << "相机型号 :" << FindExifKey(ed, "Exif.Image.Model") << std::endl; 60 std::cout << "镜头型号 :" << FindExifKey(ed, "Exif.Photo.LensModel") << std::endl; 61 std::cout << "镜头序列号 :" << FindExifKey(ed, "Exif.Photo.LensSerialNumber") << std::endl; 62 std::cout << "ISO :" << FindExifKey(ed, "Exif.Photo.ISOSpeedRatings") << std::endl; std::cout << "光圈 :" << FindExifKey(ed, "Exif.Photo.FNumber") << std::endl; 64 std::cout << "焦距 :" << FindExifKey(ed, "Exif.Photo.FocalLength") << std::endl; 65 std::cout << "快门 :" << FindExifKey(ed, "Exif.Photo.ExposureTime") << std::endl; 66 std::cout << "拍摄时间 :" << FindExifKey(ed, "Exif.Image.DateTime") << std::endl; 67 std::cout << "闪光灯 :" << FindExifKey(ed, "ExifanonCs.FlashMode") << std::endl; 68 std::cout << "水平分辨率 :" << FindExifKey(ed, "Exif.Image.XResolution") << std::endl; 69 std::cout << "垂直分辨率 :" << FindExifKey(ed, "Exif.Image.YResolution") << std::endl; 70 std::cout << "照片尺寸 :" << FindExifKey(ed, "Exif.Photo.PixelYDimension") << " x " << FindExifKey(ed, "Exif.Photo.PixelXDimension") << std::endl; 71 72 std::cout << "\n下面是原始信息:\n" << std::endl; 73 for (Exiv2::ExifData::iterator tmp = ed.begin(); tmp != ed.end(); tmp++) 76 return 0; 77 }
下一篇:Qt error: C7525: 内联变量至少需要 “/std:c++17“
Exiv2
pla文件怎么看,pla文件用什么打开?
pl1文件怎么看,pl1文件用什么打开?
pl文件怎么看,pl文件用什么打开?
pl0文件怎么看,pl0文件用什么打开?
pkt文件怎么看,pkt文件用什么打开?
pkm文件怎么看,pkm文件用什么打开?
pks文件怎么看,pks文件用什么打开?
pka文件怎么看,pka文件用什么打开?
pkh文件怎么看,pkh文件用什么打开?
pkg文件怎么看,pkg文件用什么打开?