一、简介
找出指定目录的.bmp图片,然后要把指定目录的.bmp图片的路径存到一个集合中,接着找出第一个元素即可。其实,我就是要显示第一张图片。
1、判读是否有.bmp文件类型,有的话,返回该集合
string[] dirs = Directory.GetFiles(@"d:\\My Documents\\My Pictures", "*.jpg");
如果有10张图片,那么就是10个元素了。
2、获取指定路径的文件名字
方法1(注意path包含了文件夹+文件名)
string strFileName = System.IO.Path.GetFileName(path);
3、获取指定路径的文件名字
方法1(注意path包含了文件夹+文件名)
string strPropertyName = System.IO.Path.GetExtension(path); //获取后缀。
二、先找图片、找到则显示第一张图片
注意strBmp是字符串集合啊。
注意strBmp是字符串集合啊。
注意strBmp是字符串集合啊。
/// <summary>
/// 获取文件夹下的第一张图片
/// </summary>
private string GetImageNameFunc(string Path)
{
string strImageName = null;
try
{
string[] strBmp = Directory.GetFiles(Path, "*.bmp");
if (strBmp.Length != 0)
{
strImageName = System.IO.Path.GetFileName(strBmp[0]);
}
}
catch (Exception ex)
{
MessageBox.Show("HistoryViewModel.cs::GetImageNameFunc()显示图片失败--" + ex.ToString());
LogHelper.Error("HistoryViewModel.cs::GetImageNameFunc()显示图片失败--" + ex.Message);
}
return strImageName;
}