如何知道和加载在特定文件夹中的所有图像? [英] How to know and load all images in a specific folder?

查看:160
本文介绍了如何知道和加载在特定文件夹中的所有图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序(C ++ Builder 6.0)需要知道在一个特定的文件夹中的图像的总数,然后我必须加载它们:在ImageList或ComboBoxEx ...或任何其他控件。 ..

I have an application (C++ Builder 6.0) that needs to know the total of images there are in a specific folder, and then I have to load them: in an ImageList or in a ComboBoxEx... or any other control...

我该如何做?

我知道如何在控件中加载图片,保存在TList或ImageList ...但如何知道目录中有多少文件文件,以及如何加载其中的每个图像??

I know how to load an image in a control, or to save in a TList, or in an ImageList... but How to know how many files files there are in the directory, and how to load every image in it??

我对我的英语抱歉。

推荐答案

昨天我使用C ++使用 boost :: filesystem 库。但是,如果你没有使用boost,我强烈建议你只使用Windows库。这是我的代码,如果你有兴趣:

I did something like this yesterday with C++ using the boost::filesystem library. However, if you are not using boost already, I would strongly recommend you just use the windows libraries instead. This was my code though in case you're interested:

#include <algorithm>
#include <boost/filesystem.hpp>
#include <set>

namespace fs = boost::filesystem;

typedef std::vector<fs::path> PathVector;

std::auto_ptr<PathVector> ImagesInFolder(const fs::path& folderPath) {
    std::set<std::string> targetExtensions;
    targetExtensions.insert(".JPG");
    targetExtensions.insert(".BMP");
    targetExtensions.insert(".GIF");
    targetExtensions.insert(".PNG");

    std::auto_ptr<PathVector> paths(new PathVector());

    fs::directory_iterator end;
    for(fs::directory_iterator iter(folderPath); iter != end; ++iter) {
        if(!fs::is_regular_file(iter->status())) { continue; }

        std::string extension = iter->path().extension();
        std::transform(extension.begin(), extension.end(), extension.begin(), ::toupper);
        if(targetExtensions.find(extension) == targetExtensions.end()) { continue; }

        paths->push_back(iter->path());
    }

    return paths;
}

这不会回答你的问题的部分,路径到列表框中。

This doesn't answer the part of your question about how to actually put the paths into a listbox though.

这篇关于如何知道和加载在特定文件夹中的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆