1.C# 通过Winform获取文件路径
using System.Windows.Forms;
OpenFileDialog ofd = new OpenFileDialog(); // 实例一个打开文件的对象
ofd.Filter = "(*.bmp)|*.bmp" // 实际起过滤作用的为|后面的部分
if(ofd.ShowDialog() == DialogResult.OK) //弹出打开文件的弹窗,在点确定后执行
{
string path = ofd.FileName; //将文件路径传给变量 path
}
2.C#通过Winform获取文件夹内文件的路径
using System.Collections.Generic;
using System.Windows.Forms;
using Ststem.Coll
FolderBrowerDialog fbd = new FoldBrowerDialog();//实例化一个打开文件夹的对象
fbd.Description = "请选择要导入的文件夹";
if(fbd.ShowDialog()==DialogResult.OK)
{
List<string> FilesPath = new List<string>();//创建一个List<string>用来存文件夹内的所有文件的路径
DirectoryInfo root = new DirectoryInfo(fbd.SelectedPath)//实例化一个文件夹对象
FileInfo[] files = root.GetFiles("*.bmp");//获取文件夹下的过虑后的所有文件
foreach(FileInfo file in files)
{
FilesPath.Add(file.FullName)
}
}
3.VisionPro CogImageFileTool
需要引用的dll
Cognex.VisionPro.ImageFile.dll
引用的命名空间
Using Cognex.VisionPro.ImageFile;
需用到的类为
CogImageFileTool
VisionPro导入图片需要用到的方法以及步骤
CogImageFileTool.Operator.Open(imagePath, CogImageFileModeConstants.Read);//第一个为图片路径,第二个为打开的方式;
CogImageFileTool.Run();//图片在Run()方法运行后才会开始导入。
CogImageFileTool.OutputImage//返回的是一个ICogImage接口类
CogImage8Grey Image = (CogImage8Grey) CogImageFileTool.OutputImage;//若要用到CogImage8Grey,需要显式转换一次
VisionPro存图需要用到的方法以及步骤
ICogImage image;//需要存的图片
CogImageFileTool.InputImage = image;//将要存的图片传给CogImageFileTool.InputImage
CogImageFileTool.Operator.Open(savapath,CogImageFileModeConstants.Write);
CogImageFileTool.Run();//执行操作
拓展
可在导图过程中,通过对应的事件进行下一步操作