Exemplo n.º 1
0
        private void buttonPhotoRect_Click(object sender, EventArgs e)
        {
            photoResized       = signResized = false;
            buttonSave.Enabled = false;

            using (Crop fCrop = new Crop(Path.Combine(Path.GetTempPath(), "tmp.jpg"), iniFileName, "Regionphoto"))
                fCrop.ShowDialog();

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + iniFileName))
            {
                IniInterface oIni = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));

                _photoRect = RectAndINI.ReadRectFromIni(oIni, "Regionphoto");
            }

            using (var fs = new FileStream(Path.Combine(Path.GetTempPath(), "tmp.jpg"), FileMode.Open)) //File not block
            {
                var bmp       = new Bitmap(fs);
                var sourceimg = (Bitmap)bmp.Clone();

                //Photo
                _srcPhoto             = new Bitmap(sourceimg).Clone(_photoRect, PixelFormat.Format24bppRgb);
                pictureBoxPhoto.Image = ImageComputation.ImageConvertions.ApplyRangeLevels(photodefaultlefttreshold, photodefaultrighttreshold, _srcPhoto);
            }

            this.Info("PhotoRect_Click", this.Messages("resizeImage"));
        }
Exemplo n.º 2
0
        private void buttonBarRect_Click(object sender, EventArgs e)
        {
            using (Crop fCrop = new Crop(Path.Combine(Path.GetTempPath(), "tmp.jpg"), iniFileName, "Regionbar"))
                fCrop.ShowDialog();

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + iniFileName))
            {
                IniInterface oIni = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));

                _barRect = RectAndINI.ReadRectFromIni(oIni, "Regionbar");
            }

            //BarCode
            using (var fs = new FileStream(Path.Combine(Path.GetTempPath(), "tmp.jpg"), FileMode.Open)) //File not block
            {
                var    bmp       = new Bitmap(fs);
                var    sourceimg = (Bitmap)bmp.Clone();
                string numb      = ScanQRCode(_barRect, sourceimg);
                textBoxNumber.Text = (!String.IsNullOrWhiteSpace(numb)) ? numb : textBoxNumber.Text;
                if (String.IsNullOrWhiteSpace(numb))
                {
                    textBoxNumber.ReadOnly = checkBoxBarNumber.Checked = false;
                }
            }
        }
Exemplo n.º 3
0
        private void importItems(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            if (newValuesListView.Items.Count > 0 &&
                MessageBox.Show("There are already entries in the \"New Values\" list! Do you want to delete them before importing the entries from the file?",
                                "Import",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                newValuesListView.Items.Clear();
            }

            foreach (string section in IniInterface.ReadSections(path))
            {
                string[] keyValuePairs = IniInterface.ReadKeyValuePairs(section, path);

                foreach (string keyValuePair in keyValuePairs)
                {
                    string[] keyAndValue = keyValuePair.Split('=');
                    addNewItem(section, keyAndValue[0], keyAndValue[1]);
                }
            }
        }
Exemplo n.º 4
0
        private void _scanner_ScanComplete(object sender, EventArgs e)
        {
            if (!checkBoxAuto.Checked)
            {
                using (Crop fCrop = new Crop(Path.Combine(Path.GetTempPath(), "tmp.jpg"), iniFileName, String.Empty))
                    fCrop.ShowDialog();
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + iniFileName))
                {
                    IniInterface oIni = new IniInterface(AppDomain.CurrentDomain.BaseDirectory + iniFileName);
                    _signRect  = RectAndINI.ReadRectFromIni(oIni, "Regionsign");
                    _photoRect = RectAndINI.ReadRectFromIni(oIni, "Regionphoto");
                    _barRect   = RectAndINI.ReadRectFromIni(oIni, "Regionbar");
                }

                checkBoxAuto.Checked = true;
            }

            photoResized                = signResized = false;
            buttonSave.Enabled          = false;
            buttonPhotoRect.Enabled     = buttonSignatureRect.Enabled = buttonBarRect.Enabled = true;
            buttonEditSignature.Enabled = button3.Enabled = true;

            using (var fs = new FileStream(Path.Combine(Path.GetTempPath(), "tmp.jpg"), FileMode.Open)) //File not block
            {
                var bmp       = new Bitmap(fs);
                var sourceimg = (Bitmap)bmp.Clone();

                //Photo
                _srcPhoto             = new Bitmap(sourceimg).Clone(_photoRect, PixelFormat.Format24bppRgb);
                pictureBoxPhoto.Image = ImageComputation.ImageConvertions.ApplyRangeLevels(photodefaultlefttreshold, photodefaultrighttreshold, _srcPhoto);
                this.Info("Successfuly get Photo");

                //Signature
                _srcSign = ImageComputation.ImageConvertions.MakeGrayscale3(new Bitmap(sourceimg).Clone(_signRect, PixelFormat.Format24bppRgb));
                pictureBoxSignature.Image = ImageComputation.ImageConvertions.ApplyRangeLevels(signdefaultlefttreshold, signdefaultrighttreshold, _srcSign);
                this.Info("Successfuly get Signature");

                this.Info("scanner_ScanComplete", this.Messages("resizeImage"));

                //QRCode
                string numb = String.Empty;
                if (checkBoxBarNumber.Checked)
                {
                    numb = ScanQRCode(_barRect, sourceimg);
                    textBoxNumber.Text = (!String.IsNullOrWhiteSpace(numb)) ? numb : textBoxNumber.Text;
                    this.Info("Successfuly get QRCode");
                }
                if (String.IsNullOrWhiteSpace(numb))
                {
                    textBoxNumber.ReadOnly = checkBoxBarNumber.Checked = false;
                }
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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"));
        }
Exemplo n.º 7
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");
            }
        }
Exemplo n.º 8
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));
                }
            }
        }
Exemplo n.º 9
0
        private void fMain_Load(object sender, EventArgs e)
        {
            if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName)))
            {
                IniInterface oIni = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));
                string       val  = oIni.ReadValue("Scan", "color", "Color");
                checkBoxAuto.Checked      = (oIni.ReadValue("Scan", "auto", "true") == "true") ? true : false;
                checkBoxBarNumber.Checked = (oIni.ReadValue("Scan", "barNumber", "true") == "true") ? true : false;

                textBoxNumber.ReadOnly =
                    checkBoxBarNumber.Checked;


                _color = val == "Color" ? ScanColor.Color : (
                    val == "BlackWhite" ? ScanColor.BlackWhite :
                    ScanColor.Gray);
                if (!int.TryParse(oIni.ReadValue("Scan", "dpi", "300"), out _dpi))
                {
                    _dpi = 300;
                }

                _path            = oIni.ReadValue("Save", "path", AppDomain.CurrentDomain.BaseDirectory);
                textBoxPath.Text = _path;
                _photoPrefix     = oIni.ReadValue("Save", "photoprefix", String.Empty);
                _signPrefix      = oIni.ReadValue("Save", "signprefix", String.Empty);
                _photoJP2Prefix  = oIni.ReadValue("Save", "photojp2prefix", String.Empty);
                _signJP2Prefix   = oIni.ReadValue("Save", "signjp2prefix", String.Empty);
                _photoSufix      = oIni.ReadValue("Save", "photosufix", "F");
                _signSufix       = oIni.ReadValue("Save", "signsufix", "P");
                _photoJP2Sufix   = oIni.ReadValue("Save", "photojp2sufix", "F2");
                _signJP2Sufix    = oIni.ReadValue("Save", "signjp2sufix", "P2");

                if (!int.TryParse(oIni.ReadValue("Save", "photomaxweight", "18000"), out _photoMaxWeight))
                {
                    _photoMaxWeight = 18000;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "signmaxweight", "8000"), out _signMaxWeight))
                {
                    _signMaxWeight = 8000;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "compressdpi", "300"), out _compressDPI))
                {
                    _compressDPI = 300;
                }

                if (!int.TryParse(oIni.ReadValue("Save", "photowidth", "283"), out photowidth))
                {
                    photowidth = 283;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "photoheight", "364"), out photoheight))
                {
                    photoheight = 364;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "signwidth", "283"), out signwidth))
                {
                    signwidth = 283;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "signheight", "94"), out signheight))
                {
                    signheight = 94;
                }

                if (!int.TryParse(oIni.ReadValue("Save", "signdefaultlefttreshold", "125"), out signdefaultlefttreshold))
                {
                    signdefaultlefttreshold = 125;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "signdefaultrighttreshold", "255"), out signdefaultrighttreshold))
                {
                    signdefaultrighttreshold = 255;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "photodefaultlefttreshold", "0"), out photodefaultlefttreshold))
                {
                    photodefaultlefttreshold = 0;
                }
                if (!int.TryParse(oIni.ReadValue("Save", "photodefaultrighttreshold", "255"), out photodefaultrighttreshold))
                {
                    photodefaultrighttreshold = 255;
                }

                _deviceuuid = oIni.ReadValue("Scan", "deviceuuid", AppDomain.CurrentDomain.BaseDirectory);

                _signRect  = RectAndINI.ReadRectFromIni(oIni, "Regionsign");
                _photoRect = RectAndINI.ReadRectFromIni(oIni, "Regionphoto");
                _barRect   = RectAndINI.ReadRectFromIni(oIni, "Regionbar");
            }
        }
Exemplo n.º 10
0
        private void Form_Load(object sender, EventArgs e)
        {
            _imageOut = SrcPicBox.Image = _image;

            var ratioX = (double)SrcPicBox.Width / _image.Width;
            var ratioY = (double)SrcPicBox.Height / _image.Height;

            ratio = Math.Min(ratioX, ratioY);

            // Compute the offset of the image to center it in the picture box
            var scaledWidth  = _image.Width * ratio;
            var scaledHeight = _image.Height * ratio;

            imageX = (int)((SrcPicBox.Width - scaledWidth) / 2);
            imageY = (int)((SrcPicBox.Height - scaledHeight) / 2);

            IniInterface oIni      = new IniInterface(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName));
            var          phWidht   = Convert.ToInt32(oIni.ReadValue("Save", "photowidth"));
            var          phHeight  = Convert.ToInt32(oIni.ReadValue("Save", "photoheight"));
            var          sgnWidht  = Convert.ToInt32(oIni.ReadValue("Save", "signwidth"));
            var          sgnHeight = Convert.ToInt32(oIni.ReadValue("Save", "signheight"));

            double phCoef              = (double)phWidht / phHeight;
            double sgnCoef             = (double)sgnWidht / sgnHeight;
            var    initresholdleftkey  = "signdefaultlefttreshold";
            var    initresholdrightkey = "signdefaultrighttreshold";

            switch (iniKey.ToLower())
            {
            case "photo":
            {
                coef = phCoef;
                initresholdleftkey  = "photodefaultlefttreshold";
                initresholdrightkey = "photodefaultrighttreshold";
            }
            break;

            case "sign":
            {
                coef = sgnCoef;
                initresholdleftkey  = "signdefaultlefttreshold";
                initresholdrightkey = "signdefaultrighttreshold";
            }
            break;

            default:
            {
                coef = 1;
                initresholdleftkey  = "signdefaultlefttreshold";
                initresholdrightkey = "signdefaultrighttreshold";
            }
            break;
            }

            if (!int.TryParse(oIni.ReadValue("Save", initresholdleftkey, "0"), out defaultlefttreshold))
            {
                defaultlefttreshold = 125;
            }
            if (!int.TryParse(oIni.ReadValue("Save", initresholdrightkey, "255"), out defaultrighttreshold))
            {
                defaultrighttreshold = 255;
            }

            pictureBoxOut.Image = ImageComputation.ImageConvertions.ApplyRangeLevels(defaultlefttreshold, defaultrighttreshold, _imageOut);
            histogram.DrawHistogram(GetHistogram((Bitmap)_imageOut));
            rangeLevels.Value = new DevExpress.XtraEditors.Repository.TrackBarRange(defaultlefttreshold, defaultrighttreshold);
        }
Exemplo n.º 11
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);
            }
        }