簡體   English   中英

是否有用於加載圖像文件夾的 Magick++ function?

[英]Is there a Magick++ function for loading a folder of images?

我一直在將 Magick++ 用於與圖像相關的程序,但我一直無法找到一種方法來從文件夾中批量加載圖像並進行處理。

如果在庫中沒有辦法做到這一點,有沒有辦法用<filesystem>做到這一點? (通過獲取目錄中的文件名?)

我相信我已經找到了解決方案,但要小心,我是初學者,下面的代碼可能不符合標准。 如果有更好、更模塊化的方法,請分享。

#include <string>
#include <iostream>
#include <filesystem>
#include <Magick++.h>

using namespace Magick;
namespace fs = std::filesystem;

int main(int argc,char **argv) {
    InitializeMagick(*argv);
    //sample number
    Image image[10];

    std::string doc = fs::current_path();
    int i = 0;

    for (const auto & entry : fs::directory_iterator(doc)){
        try{
        i++;
        std::cout << entry.path() << std::endl;
        image[i].read(entry.path());
        image[i].display();
        }
        //These below exceptions occur if the file is not an image, it will skip if the file is not an image
        catch(Magick::ErrorMissingDelegate &error){
            continue;
        }
        catch(Magick::ErrorCorruptImage &error){
            continue;
        }
    }


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM