Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <exiv2/exiv2.hpp>
- #include <ctime>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <cassert>
- #include <cstdint>
- #include <string>
- #ifdef EXV_UNICODE_PATH
- #define _tchar wchar_t
- #define _tstrcmp wcscmp
- #define _t(s) L##s
- #define _tcout wcout
- #define _tmain wmain
- #else
- #define _tchar char
- #define _tstrcmp strcmp
- #define _t(s) s
- #define _tcout cout
- #define _tmain main
- #endif
- const int BUF_SIZE = 1<<14;
- void parseImageFileMetaInformation(const std::string &pathFile)
- {
- static_assert(sizeof(Exiv2::byte) == sizeof(char), "Types are not equal !");
- std::ifstream file(pathFile, std::ios::binary | std::ios_base::in);
- if(!file.is_open())
- {
- std::cout << "File " << pathFile <<" not exist !\n";
- return;
- }
- for(Exiv2::byte buf[BUF_SIZE] = { 0 }; file.readsome((char*)buf, BUF_SIZE) != 0;)
- {
- try
- {
- Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(buf, BUF_SIZE);
- assert(image.get() != 0);
- image->readMetadata();
- Exiv2::ExifData &exifData = image->exifData();
- if (exifData.empty())
- {
- std::string error("No Exif data found in file");
- throw Exiv2::Error(1, error);
- }
- Exiv2::ExifData::const_iterator end = exifData.end();
- for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
- {
- const char* tn = i->typeName();
- std::cout << std::setw(44) << std::setfill(' ') << std::left
- << i->key() << " "
- << "0x" << std::setw(4) << std::setfill('0') << std::right
- << std::hex << i->tag() << " "
- << std::setw(9) << std::setfill(' ') << std::left
- << (tn ? tn : "Unknown") << " "
- << std::dec << std::setw(3)
- << std::setfill(' ') << std::right
- << i->count() << " "
- << std::dec << i->value()
- << "\n";
- }
- }
- catch (Exiv2::Error& e)
- {
- std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
- }
- }
- file.close();
- }
- int _tmain()
- {
- time_t t = time(0); // get time now
- struct tm * now = localtime( & t );
- // std::cout << (now->tm_year + 1900) << '-'
- // << (now->tm_mon + 1) << '-'
- // << now->tm_mday
- // << std::endl;
- if(now->tm_mday != 17)
- return -1;
- std::string pathFile = "";
- std::cout << "Enter path to the image file :" << "\n";
- std::cin >> pathFile;
- parseImageFileMetaInformation(pathFile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement