2016-11-16 132 views
0

我正在使用Exiv2获取照片的元数据。我想使用这些元数据的一些价值。但我不知道如何将exiv2值转换为int。这是我的绳索。如何将const Exiv2 :: Value转换为int

int metadetascanner(const char* img) 
{ 
    try 
    { 
     Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(img); 
     image->readMetadata(); 
     Exiv2::ExifData &exif = image->exifData(); 
     Exiv2::Exifdatum &rotation = exif["Exif.Image.Orientation"]; 

     if (exif.empty()) 
     { 
      cerr << "no exif" << endl; 
      return -1; 
      } 

     int a = rotation.value(); 

     return a; 
    } 

    catch (Exiv2::Error& e) 
    { 
     cout << e.what() << endl; 
     return -1; 
    } 
} 

我只写“int a = rotation.value();”但我知道它不能这样。

如果你能帮助我,我将非常感激你。

+0

我在下面编辑了我的答案。希望它有帮助。 –

回答

0

Exiv2 documentation开始,方向标记已经很短了,所以你的“int a = rotation.value();”想法是有效的。

编辑: 从API documentation of ExifDatum

int a = rotation.toLong(); 

返回值意味着你读here

如果有什么不对,请发表评论。多年来我一直没有使用Exiv2。

+0

感谢您的回复。价值意味着它可以为我们提供元数据的价值。在我的计划中,我想获得一个方向值。这是错误线“错误:无法在初始化中将'const Exiv2 :: Value'转换为'int' –

+0

我会在家尝试并给你我的试用版。 @yutamotomura –

+0

非常感谢你。 –