[英]How do I display a scanned Image automatically in a Picturebox?
I need upload image into PictureBox
automatically after scan. 扫描后我需要自动将图像上传到PictureBox
。
This is PictureBox's name PictureBox ptbImgDocEmp
这是PictureBox的名称PictureBox ptbImgDocEmp
This is the class of scanner 这是扫描仪的类别
Scanner.cs
public class Scanner
{
Device oDevice;
Item oItem;
CommonDialogClass dlg;
public Scanner()
{
dlg = new CommonDialogClass();
try
{
oDevice = dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
}
catch (Exception Exp)
{ MessageBox.Show("printer not detected");}
}
This is a Scanner Button 这是一个扫描仪按钮
private void btnSca_Click(object sender, EventArgs e)
{
Scanner oScanner = new Scanner();
oScanner.Scann();
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "test.jpg";
saveFileDialog.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ptbImgDocEmp.Image = Image.FromFile(saveFileDialog.FileName);
ptbImgDocEmp.Refresh();
}
}
To get the last file created, assuming their names are ascending you can use this: 要获得最后创建的文件,假设它们的名称是升序的,可以使用以下命令:
using System.IO;
..
string path = @"C:\Users\MyComputer\Documents\Scanned Documents";
var files = Directory.GetFiles(yourPath);
var filesSorted = files.OrderBy(x => x);
string lastFile = filesSorted.Last();
If your scanner software creates the files with names in non-strictly ascending order you can use this code: 如果您的扫描仪软件以非严格升序的名称创建文件,则可以使用以下代码:
var files = Directory.GetFiles(yourPath);
List<FileInfo> filesInfoList = new List<FileInfo>();
foreach(string f in files ) filesInfoList.Add(new FileInfo(f));
var filesSorted = filesInfoList.OrderBy(x => x.CreationTime);
string lastFile = filesSorted.Last().FullName;
Then you can write 那你可以写
ptbImgDocEmp.Image = Image.FromFile(lastFile );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.