• 大小: 81KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: c#  wia  winform  

资源简介

c# winform wia 调用扫描仪demo,c# winform wia 调用扫描仪demo

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using WIA;
using System.Text.Regularexpressions;


namespace scanner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox2.Text = Properties.Resources.filePath;
            //如果不存在就创建file文件夹 
            if (Directory.Exists(Properties.Resources.filePath) == false)
            {
                Directory.CreateDirectory(Properties.Resources.filePath); 
            } 
           


        }

        private void button1_Click(object sender EventArgs e)
        {
            if(textBox1.Text == null || textBox1.Text == ““){
                MessageBox.Show(“请先输入编号前缀(英文字符)!““提示“);
                return ;
            }

            ImageFile imageFile = null;
            CommonDialogClass cdc = new WIA.CommonDialogClass();

            try
            {
                imageFile = cdc.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType
                                                 WIA.WiaImageIntent.TextIntent
                                                 WIA.WiaImageBias.MaximizeQuality
                                                 “{00000000-0000-0000-0000-000000000000}“
                                                 true
                                                 true
                                                 false);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                imageFile = null;
            }
           
            if (imageFile != null)
            {
               
                //imageFile.SaveFile(Properties.Resources.filePath + textBox1.Text + “.pdf“);
                imageFile.SaveFile(Properties.Resources.filePath + textBox1.Text + “.bmp“);
                using (FileStream stream = new FileStream(Properties.Resources.filePath + textBox1.Text + “.bmp“ FileMode.Open FileAccess.Read FileShare.Read))
                {
                  pictureBox1.Image = Image.FromStream(stream);
                }
                //File.Delete(Properties.Resources.filePath + textBox1.Text + “.bmp“);
            }


        }

        private void textBox1_TextChanged(object sender EventArgs e)
        {

            if (textBox1.Text == null || textBox1.Text == ““)
            {
               
                return;
            }

            //遍历文件夹根据编号前缀自动生成下一级编号
            DirectoryInfo dir = new DirectoryInfo(Properties.Resources.filePath);
            FileInfo[] fileList = dir.GetFiles();

            int maxNum = -1;
            int numberLength = -1;

            for (int i = 0; i < fileList.Length; i++) {
                if (fileList[i].Name.StartsWith(text

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-18 19:08  scanner\
     目录           0  2019-01-18 19:47  scanner\scanner\
     文件        5592  2019-01-18 20:57  scanner\scanner\Form1.Designer.cs
     文件        4259  2019-01-20 11:47  scanner\scanner\Form1.cs
     文件        5817  2019-01-18 20:57  scanner\scanner\Form1.resx
     文件         499  2019-01-18 19:07  scanner\scanner\Program.cs
     目录           0  2019-01-18 19:07  scanner\scanner\Properties\
     文件        1426  2019-01-18 19:07  scanner\scanner\Properties\AssemblyInfo.cs
     文件        3138  2019-01-18 21:05  scanner\scanner\Properties\Resources.Designer.cs
     文件        5911  2019-01-18 21:05  scanner\scanner\Properties\Resources.resx
     文件        1094  2019-01-18 19:07  scanner\scanner\Properties\Settings.Designer.cs
     文件         249  2019-01-18 19:07  scanner\scanner\Properties\Settings.settings
     文件          77  2019-01-18 19:47  scanner\scanner\app.config
     目录           0  2019-01-18 19:07  scanner\scanner\bin\
     目录           0  2019-01-18 19:57  scanner\scanner\bin\Debug\
     文件       34816  2019-01-18 19:10  scanner\scanner\bin\Debug\Interop.WIA.dll
     文件       11776  2019-01-20 11:47  scanner\scanner\bin\Debug\scanner.exe
     文件          77  2019-01-18 19:47  scanner\scanner\bin\Debug\scanner.exe.config
     文件       30208  2019-01-20 11:47  scanner\scanner\bin\Debug\scanner.pdb
     文件       11600  2019-01-24 18:55  scanner\scanner\bin\Debug\scanner.vshost.exe
     文件          77  2019-01-18 19:47  scanner\scanner\bin\Debug\scanner.vshost.exe.config
     文件         490  2013-06-18 20:28  scanner\scanner\bin\Debug\scanner.vshost.exe.manifest
     目录           0  2019-01-18 19:07  scanner\scanner\obj\
     目录           0  2019-01-18 19:07  scanner\scanner\obj\x86\
     目录           0  2019-01-20 11:47  scanner\scanner\obj\x86\Debug\
     文件        5420  2019-01-20 11:42  scanner\scanner\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6599  2019-01-20 11:47  scanner\scanner\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件       34816  2019-01-18 19:10  scanner\scanner\obj\x86\Debug\Interop.WIA.dll
     目录           0  2019-01-18 21:05  scanner\scanner\obj\x86\Debug\TempPE\
     文件        4608  2019-01-18 21:05  scanner\scanner\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll
     文件         180  2019-01-18 20:59  scanner\scanner\obj\x86\Debug\scanner.Form1.resources
............此处省略9个文件信息

评论

共有 条评论