Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include <exiv2/exiv2.hpp>
  2.  
  3. #include <ctime>
  4.  
  5. #include <iostream>
  6.  
  7. #include <fstream>
  8. #include <iomanip>
  9. #include <cassert>
  10. #include <cstdint>
  11. #include <string>
  12.  
  13. #ifdef EXV_UNICODE_PATH
  14. #define _tchar wchar_t
  15. #define _tstrcmp wcscmp
  16. #define _t(s) L##s
  17. #define _tcout wcout
  18. #define _tmain wmain
  19. #else
  20. #define _tchar char
  21. #define _tstrcmp strcmp
  22. #define _t(s) s
  23. #define _tcout cout
  24. #define _tmain main
  25. #endif
  26.  
  27. const int BUF_SIZE = 1<<14;
  28.  
  29. void parseImageFileMetaInformation(const std::string &pathFile)
  30. {
  31. static_assert(sizeof(Exiv2::byte) == sizeof(char), "Types are not equal !");
  32.  
  33. std::ifstream file(pathFile, std::ios::binary | std::ios_base::in);
  34. if(!file.is_open())
  35. {
  36. std::cout << "File " << pathFile <<" not exist !\n";
  37. return;
  38. }
  39.  
  40. for(Exiv2::byte buf[BUF_SIZE] = { 0 }; file.readsome((char*)buf, BUF_SIZE) != 0;)
  41. {
  42. try
  43. {
  44. Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(buf, BUF_SIZE);
  45.  
  46. assert(image.get() != 0);
  47.  
  48. image->readMetadata();
  49.  
  50. Exiv2::ExifData &exifData = image->exifData();
  51. if (exifData.empty())
  52. {
  53. std::string error("No Exif data found in file");
  54. throw Exiv2::Error(1, error);
  55. }
  56.  
  57. Exiv2::ExifData::const_iterator end = exifData.end();
  58. for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
  59. {
  60. const char* tn = i->typeName();
  61. std::cout << std::setw(44) << std::setfill(' ') << std::left
  62. << i->key() << " "
  63. << "0x" << std::setw(4) << std::setfill('0') << std::right
  64. << std::hex << i->tag() << " "
  65. << std::setw(9) << std::setfill(' ') << std::left
  66. << (tn ? tn : "Unknown") << " "
  67. << std::dec << std::setw(3)
  68. << std::setfill(' ') << std::right
  69. << i->count() << " "
  70. << std::dec << i->value()
  71. << "\n";
  72. }
  73. }
  74. catch (Exiv2::Error& e)
  75. {
  76. std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
  77. }
  78. }
  79. file.close();
  80. }
  81.  
  82. int _tmain()
  83. {
  84. time_t t = time(0); // get time now
  85. struct tm * now = localtime( & t );
  86. // std::cout << (now->tm_year + 1900) << '-'
  87. // << (now->tm_mon + 1) << '-'
  88. // << now->tm_mday
  89. // << std::endl;
  90.  
  91. if(now->tm_mday != 17)
  92. return -1;
  93.  
  94. std::string pathFile = "";
  95. std::cout << "Enter path to the image file :" << "\n";
  96. std::cin >> pathFile;
  97.  
  98. parseImageFileMetaInformation(pathFile);
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement