Пример #1
0
        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            File.Delete(Path.Combine(Path.GetTempPath(), "tmp.jpg"));
            File.Delete(Path.Combine(Path.GetTempPath(), "tmpdpi.jpg"));
            File.Delete(Path.Combine(Path.GetTempPath(), "tmpcorrection.jpg"));

            if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName)))
            {
                //Connect to Ini File "Config.ini" in current directory
                IniInterface oIni = new IniInterface(AppDomain.CurrentDomain.BaseDirectory + iniFileName);
                oIni.WriteValue("Scan", "auto", checkBoxAuto.Checked ? "true" : "false");
                oIni.WriteValue("Scan", "barNumber", checkBoxBarNumber.Checked ? "true" : "false");
                this.Info("Save to ini file \"barNumber\" and \"auto\" flags");
            }
        }
Пример #2
0
        private void exportItems(string path, bool overwrite)
        {
            if (overwrite && File.Exists(path))
            {
                File.Delete(path);
            }

            foreach (ListViewItem item in newValuesListView.Items)
            {
                IniInterface.WriteValue(item.Text, item.Name, item.SubItems[2].Text, path);
            }
        }
Пример #3
0
        private void buttonClearSkannerUUID_Click(object sender, EventArgs e)
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + iniFileName))
            {
                //Connect to Ini File "Config.ini" in current directory
                IniInterface oIni = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));
                oIni.WriteValue("Scan", "deviceuuid", String.Empty);
            }
            string _olddeviceuuid = _deviceuuid;

            _deviceuuid = String.Empty;
            this.Info(String.Format("Droped old scanner with uuid=\"{0}\"", _olddeviceuuid), this.Messages("scannerUUIDDroped"));
        }
Пример #4
0
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            string _oldPath         = textBoxPath.Text;
            FolderBrowserDialog fld = new FolderBrowserDialog()
            {
                SelectedPath = textBoxPath.Text
            };

            if (fld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBoxPath.Text = _path = fld.SelectedPath;
                if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName)))
                {
                    //Connect to Ini File "Config.ini" in current directory
                    IniInterface oIni = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));
                    oIni.WriteValue("Save", "path", textBoxPath.Text);
                    this.Info(String.Format("Change path to save files from \"{0}\", to \"{1}\"", _oldPath, _path));
                }
            }
        }
Пример #5
0
        void Scan(ScanColor clr, int dpi, string deviceuuid, string iniPath)
        {
            string deviceid;

            //Choose Scanner
            if (String.IsNullOrEmpty(deviceuuid))
            {
                CommonDialog class1 = new CommonDialog();
                Device       d      = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
                if (d == null)
                {
                    return; //no scanner chosen
                }
                deviceid = d.DeviceID;
                if (File.Exists(iniPath))
                {
                    //Connect to Ini File "Config.ini" in current directory
                    IniInterface oIni = new IniInterface(iniPath);
                    oIni.WriteValue("Scan", "deviceuuid", deviceid);
                    CertificateScanner.ExceptionDecor.ExceptionDecorator.Info(String.Format("New scanner with uuid=\"{0}\" added", deviceid));
                }
            }
            else
            {
                deviceid = deviceuuid;
            }
            CommonDialog WiaCommonDialog = new CommonDialog();
            bool         hasMorePages    = true;
            int          x        = 0;
            int          numPages = 0;

            while (hasMorePages)
            {
                //Create DeviceManager
                DeviceManager manager = new DeviceManager();
                Device        WiaDev  = null;
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == deviceid)
                    {
                        Properties infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break;
                    }
                }
                //Start Scan
                ImageFile img  = null;
                Item      Item = WiaDev.Items[1] as Item;
                //set properties //BIG SNAG!! if you call WiaDev.Items[1] apprently it erases the item from memory so you cant call it again
                Item.Properties["6146"].set_Value((int)clr);//Item MUST be stored in a variable THEN the properties must be set.
                Item.Properties["6147"].set_Value(dpi);
                Item.Properties["6148"].set_Value(dpi);
                try
                {//WATCH OUT THE FORMAT HERE DOES NOT MAKE A DIFFERENCE... .net will load it as a BITMAP!
                    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" /*WIA.FormatID.wiaFormatJPEG*/, false);
                    //process image:
                    //Save to file and open as .net IMAGE
                    string varImageFileName = Path.GetTempFileName();
                    if (File.Exists(varImageFileName))
                    {
                        //file exists, delete it
                        File.Delete(varImageFileName);
                    }
                    img.SaveFile(varImageFileName);
                    Image ret;
                    using (var fs = new FileStream(varImageFileName, FileMode.Open)) //File not block
                    {
                        var bmp = new Bitmap(fs);
                        ret = (Bitmap)bmp.Clone();
                        EventHandler <WiaImageEventArgs> temp = Scanning;
                        if (temp != null)
                        {
                            temp(this, new WiaImageEventArgs(ret));
                        }
                    }
                    numPages++;
                    img = null;
                    File.Delete(varImageFileName);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    Item = null;
                    //determine if there are any more pages waiting
                    Property documentHandlingSelect = null;
                    Property documentHandlingStatus = null;

                    foreach (Property prop in WiaDev.Properties)
                    {
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
                        {
                            documentHandlingSelect = prop;
                        }
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
                        {
                            documentHandlingStatus = prop;
                        }
                    }
                    hasMorePages = false; //assume there are no more pages
                    if (documentHandlingSelect != null)
                    //may not exist on flatbed scanner but required for feeder
                    {
                        //check for document feeder
                        if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                        {
                            hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                        }
                    }
                    x++;
                }
            }
            EventHandler tempCom = ScanComplete;

            if (tempCom != null)
            {
                tempCom(this, EventArgs.Empty);
            }
        }