如何在vc中读入一个文件夹里面的所有图像
来源:互联网 发布:淘宝没有促销活动 编辑:程序博客网 时间:2024/05/01 04:11
1:
CString strDir;//储存文件夹路径
CFileFind ff;
......... /* 获取文件夹路径*/
strDir+="*.*";//如果是只需要某种文件,怎么替换应该很简单了吧
BOOL res =ff.FindFile(strDir);
while(res)
{
res=ff.FindNextFile();
if(ff.IsDirectory){/*如果是文件夹就XXXXX*/};
else
{ //ff.GetFileName就是每个文件名,比如如下设计
CString s;
s.Format("%s",ff.GetFileName());
///干你想干的事情吧
///不过注意有时候会把你看不到得系统文件也读出来
}
}
2:
VC代码,功能很完整。可以只选择文件夹中的一幅图像,然后点OK,会自动遍历
整个文件夹。读取各个文件的完整路径到一个vector中,并不把所有图像读进内存,这样可以
节省不必要的内存开销。 在处理函数中,根据这些完整的路径,打开一个处理一个释放一个。
直到处理完所有图像。
- C/C++ code
int CBatch::FileOpenEx()
{
int counter=0;
CString ss="";
pair<map<CString,CString>::iterator,bool> Pair_Insert;
// TODO: Add your command handler code here
int nimg=0;
CString ftitle,fname,fpath,fpathname,froot;
CString mp[7];
static char szFilter[] = "*.BMP|*.BMP|All Files(*.*)|*.*||";
CFileDialog FileDlg( TRUE, NULL, NULL,OFN_HIDEREADONLY, szFilter );
if( FileDlg.DoModal() == IDOK )
{
fpathname=FileDlg.GetPathName();
CFileFind finder;
finder.FindFile(fpathname);
finder.FindNextFile();
froot=finder.GetRoot();
BOOL bResult;
fpathname=froot+_T("//*.*"); //找到该文件的文件夹,
bResult=finder.FindFile(fpathname); //然后从头开始一个一个遍历
while (bResult)
{
counter++;
bResult=finder.FindNextFile();
if(finder.IsDots()) continue;
if(finder.IsDirectory()) continue;
fname=finder.GetFileName();
if("bmp" !=fname.Right(3) && "BMP" !=fname.Right(3) ) continue;
//找到了一个bmp文件,开始提取相关信息
FPRO fpro;//自定义的一个结构体
fpro.filePath =finder.GetFilePath(); // 路径和文件名,包括扩展名。
fpro.fileName = finder.GetFileName();
fpro.fileTitle = finder.GetFileTitle();
m_imvec.push_back(fpro);
}// while
}// if
BatchProcess();
return 1 ;
}
int CBatch::BatchProcess()
{
CMainFrame * pMain = (CMainFrame*) AfxGetApp()->m_pMainWnd;
CBlurEstimation3View *pView = (CBlurEstimation3View*) pMain->GetActiveView();
IMIter it_start,it_end,it;
for (it= m_imvec.begin(); it!=m_imvec.end(); ++it)
{
CString Dir = it->filePath;
if (dib.Load(Dir))
{
CClientDC dc(pView);
dib.SetPalette(&dc);
dib.Draw(&dc);
}
else
continue;
int width = dib.m_Width;
int height = dib.m_Height;
int srcLineBytes = dib.m_DataSize/height;
int residual= 4 - width%4;
if(residual ==4)
residual =0;
if(dib.m_DataSize == width*height)
residual = 0;
width = width - width%4;
#pragma region
//分配内存,读取1D图像数据
BYTE *pBits = new BYTE[width*height];
//分配内存,读取2D 图像数据
// BYTE **p2DBits = new BYTE *[height];
// for(int i=0; i<height; ++i)
// p2DBits[i] = new BYTE[width];
BYTE pixel;
for(int i=0; i<height;++i)
for(int j=0; j<width; ++j)
{
pixel = dib.m_pDibBits[srcLineBytes*i +j];
// p2DBits[i][j] = pixel;
pBits[i*width+j] = pixel;
}
#pragma endregion
float param = 0;
//***************************************************************
// 此处添加代码
// 处理
// end此处添加代码
//****************************************************************
CString str;
str.Format("%f",param);
it->param = str;
// for(i=0; i<height;++i)
// delete []p2DBits[i];
// delete []p2DBits;
delete []pBits;
}
return 1;
}
- 如何在vc中读入一个文件夹里面的所有图像
- 利用matlab读入文件夹中所有图像
- 在VC中怎么遍历一个文件夹下的所有文件和文件夹
- 在VC中怎么遍历一个文件夹下的所有文件和文件夹?
- 在java中高效复制一个文件夹里面所有的内容
- matlab一个文件夹里面包含多个文件夹,读取所有文件夹内的图像路径生成list
- C#如何遍历一个文件夹下面所有的文件、包括子文件夹里面的文件?
- Matlab如何读入指定文件夹里的所有图片
- 如何遍历一个文件夹下的所有文件与目录在(Javascript中)
- matlab中怎样读取一个文件夹里面的指定类型的所有文件的名称?
- 如何在命令行提示符里面删除文件夹下的所有文件
- 替换字符串在一个文件夹中所有的文件
- 在一个文件夹下面的所有文件中查找字符串
- VC中如何得到一个文件夹的路径
- 在VC中做一个选择文件夹的对话框
- 在VC中做一个选择文件夹的对话框
- 在VC中做一个选择文件夹的对话框 (转载)
- OpenCV读入的图像如何显示在窗体上
- 一些有用的时间函数
- Sql级联删除的创建 数据库关系图
- #pragma用法大全
- eclipse3.3.2+cdt4.0.3+MingGw环境下编译c++
- SQL Server SQL语句导入导出大全
- 如何在vc中读入一个文件夹里面的所有图像
- 将会改变人一生的五句话……
- 单件模式——JAVA的两种实现
- Mcafee 升级包下载地址
- 动态规划(dynamic programming)
- 开源软交换ASTERISK学习日记(二)
- JavaScript操作帧frame对象
- 《coraline》观后感:Be careful what you wish for
- js操作 img