winform中获取指定文件夹下的所有图片
方法一:
C#的IO自带了一个方法
DirectoryInfo dir = new DirectoryInfo("文件夹名称");
dir.getFiles();//这个方法返回值就是Fileinfo类型的数组
再将获取的图片一一存入List数组中,需要从list中找即可
public String exePath = Application.StartupPath; //绝对路径
DirectoryInfo dir = new DirectoryInfo("c:\\test");
//相对路径,和程序exe同目录下
//DirectoryInfo dir = new DirectoryInfo(@"test");
FileInfo[] fileInfo = dir.GetFiles();
List<string> fileNames = new List<string>();
foreach (FileInfo item in fileInfo)
{
fileNames.Add(item.Name);
} //图片展示
for (int i = 0; i < fileNames.Count; i++)
{
string fileName = fileNames[i];
this.panelAutographPic.Controls.Add(new PictureBox
{
BackColor = System.Drawing.Color.Transparent,
BackgroundImageLayout = ImageLayout.Stretch,
Width = 300,
Height = 200,
BackgroundImage = Image.FromFile(exePath + "../test/" + fileName)
});
}
方法二:
将获取的图片一一存入ListBox中,需要从listBox中找即可
ListBox listBox1 = new ListBox();
private void Get_Folder(string FilePath)
{
if (Directory.Exists(FilePath))
{
foreach (string d in Directory.GetFileSystemEntries(FilePath))
{
Image img = Image.FromFile(d);
if (File.Exists(d) && img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg) ||
img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif) ||
img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp) ||
img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
{
listBox1.Items.Add(d.ToString());
}
}
}
else
{
MessageBox.Show("文件夹不存在!");
}
}
//调用
Get_Folder(@"指定文件夹名");
winform中获取指定文件夹下的所有图片的更多相关文章
- Python获取指定文件夹下的文件名
本文采用os.walk()和os.listdir()两种方法,获取指定文件夹下的文件名. 一.os.walk() 模块os中的walk()函数可以遍历文件夹下所有的文件. os.walk(top, t ...
- 脚本工具(获取某个文件夹下的所有图片属性批量生成css样式)
问题描述: 由于有一次工作原因,就是将某个文件夹下的所有图片,通过CSS描述他们的属性,用的时候就可以直接引用.但是我觉得那个文件夹下的图片太多,而且CSS文件的格式又有一定的规律,所有想通过脚本来生 ...
- Windows 下通过DOS命令获取指定文件夹下所有文件的全路径
1.在你要获取路径的文件夹下 新建文本文档 (.txt) 文件, 2.输入以下内容保存 DIR *.* /S/B >LIST.TXT /s 表示递归 3. 将文件后缀改成 .bat 4.双击运行 ...
- [C#]获取指定文件夹下的所有文件名(递归)
典型的递归方法: //定义一个list集合 List<String> list = new List<String>(); public void director(strin ...
- IO流(7)获取指定文件夹下的所有文件
/* * 把E:\JavaSE目录下所有的java结尾的文件的绝对路径给输出在控制台. * * 分析: * A:封装目录 * B:获取该目录下所有的文件或者文件夹的File数组 * C:遍历该File ...
- java获取指定文件夹下的所有文件名
package com.henu.util; import java.io.File; public class TakeFilePathAndName { public static void ma ...
- python获取指定文件夹下的文件路径
#!/usr/bin/python# -*- coding: UTF-8 -*-# @date: 2018/1/6 23:08# @name: tmp2# @author:vickey-wu impo ...
- python获取指定文件夹下的文件和文件夹
import os filepaths = []; dirpaths = []; pathName = r'C:\anfei\json\20191128' for root, dirs, files ...
- php获取指定文件夹中文件名称
/** * php获取指定文件夹中文件名称 * @author jackie <2018.10.10> */ public static function getFileName($fil ...
随机推荐
- 使用secureCRT和Telnet将文件压缩导出到Ubuntu中,到Ubuntu中加压缩发现:tar解压包的时候出现错误gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
细节描述: 问题如题所示:查找博客园和CSDN上查找问题,得到问题解决方法大致如下: 1 修改解压缩命令: 由 tar zxvf software_package.tar.gz变为tar xvf so ...
- Oracle报错ORA-12516 TNS:listener could not find available handler with matching protocol stack
解决办法定位原因-- 以sysdba身份登陆PL/SQL sqlplus / as sysdba;-- 查看当前连接进程数SQL>select count(*) from v$process;- ...
- 快速实现office文档在线预览展示(doc,docx,xls,xlsx,ppt,pptx)
微软:https://view.officeapps.live.com/op/view.aspx?src=(输入你的文档在服务器中的地址):
- JMeter 测试 ActiveMq
JMeter 测试 ActiveMq 的资料非常少, 我花了大量的时间才研究出来 关于ActiveMq 的文章请参考我另外的文章. 阅读目录 版本号: ActiveMq 版本号: 5.91 Jmet ...
- 1.3 History of Android Plug-in Programing
In July 27, 2012 , it was the first milestone in Android plug-in technology. Yimin Tu(mmin18 o ...
- 【安富莱二代示波器教程】第16章 附件A---电阻屏触摸校准
第16章 附件A---电阻屏触摸校准 二代示波器的触摸校准比较简单,随时随地都可以做触摸校准,按下K1按键即可校准.有时候我们做触摸校准界面,需要在特定的界面才可以进入触摸校准状态,非常繁琐 ...
- [Swift]LeetCode229. 求众数 II | Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The a ...
- [Swift]LeetCode415. 字符串相加 | Add Strings
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...
- 002-J2EE-tomcat的配置
在配置之前我们要先下载一个Tomcat,登入以下网址... 下载解压完了之后可以把里面多余的东西删掉,当然也可以选择不删. 还有这里的也是 如果已经有了 classes 和l ib 目录了, 就不用再 ...
- BBS论坛(二十九)
29.帖子详情页布局 (1)front/hooks.py @bp.errorhandler def page_not_found(): return render_template('front/fr ...