ブーストを使用するのは初めてです。それを使用して、画像のコレクションをロードします。問題は、フォルダー内の画像の数が増え続け、最終的にはすべての画像を表示プログラムに追加したくないということです。私は OS X で C++ を使用しています。
このサンプルコードを調整して、ディレクトリの上部または下部から 30 枚の画像のみをロードするようにするにはどうすればよいですか? 最新のファイルだけをロードするのは素晴らしいことですが、これを変更するだけで解決できます。残念ながら、私のループで (it <30) と言うだけでは機能しません。これは fs::directory_iterator と同等である必要があるためです。
コード例:
fs::path pPhoto( photobooth_texture_path );
for ( fs::directory_iterator it( pPhoto ); it != fs::directory_iterator(); ++it )
{
if ( fs::is_regular_file( *it ) )
{
// -- Perhaps there is a better way to ignore hidden files
string photoFileName = it->path().filename().string();
if( !( photoFileName.compare( ".DS_Store" ) == 0 ) )
{
photoboothTex.push_back( gl::Texture( loadImage( photobooth_texture_path + photoFileName ), mipFmt) );
cout << "Loaded: " << photoFileName <<endl;
}
}
}
編集:これが私がやった方法です。2 つの方法のハイブリッドのようなものですが、逆方向に並べ替える必要がありました。世界で最もクリーンなものではありませんが、私は彼らのアイデアを私が理解しているC++のフレーバーに変換する必要がありました
vector<string> fileList;
int count = 0;
photoboothTex.clear();//clear this out to make way for new photos
fs::path pPhoto( photobooth_texture_path );
for ( fs::directory_iterator it( pPhoto ); it != fs::directory_iterator(); ++it ) {
if ( fs::is_regular_file( *it ) )
{
// -- Perhaps there is a better way to ignore hidden files
string photoFileName = it->path().filename().string();
if( !( photoFileName.compare( ".DS_Store" ) == 0 ) )
{
fileList.push_back(photoFileName);
}
}
}
for (int i=(fileList.size()-1); i!=0; i--) {
photoboothTex.push_back( gl::Texture( loadImage( photobooth_texture_path + fileList[i%fileList.size()] )) );
cout << "Loaded Photobooth: " << fileList[i%fileList.size()] <<endl;
if(++count ==40) break; //loads a maximum of 40 images
}