0

您好我正在尝试使用 exiv2 从图像中读取元数据,但是打开文件时出现以下错误:Microsoft C++ 异常:std::bad_alloc

我正在使用默认的 c++ Visual Studio 2019 编译器。

#include <iostream>
#include "exiv2/exiv2.hpp"

inline bool file_exists(const std::string& name) {
    struct stat buffer;
    return (stat(name.c_str(), &buffer) == 0);
}

int main(void)
{
    try
    {
        Exiv2::XmpParser::initialize();
        ::atexit(Exiv2::XmpParser::terminate);
#ifdef EXV_ENABLE_BMFF
        Exiv2::enableBMFF();
#endif

        const char* file = "E:/img/DJI_0001.jpg";
        if (!file_exists(file)) return 0;
        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
        assert(image.get() != 0);
        image->readMetadata();
    }
    catch (Exiv2::Error& e) {
        std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
        return -1;
    }
4

0 回答 0