Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            _scanner               = new ADFScan();
            _scanner.Scanning     += new EventHandler <WiaImageEventArgs>(_scanner_Scanning);
            _scanner.ScanComplete += new EventHandler(_scanner_ScanComplete);
            ScanColor selectedColor = (ScanColor)_colors[comboBox1.SelectedIndex];
            int       dpi           = (int)numericUpDown1.Value;

            _scanner.BeginScan(selectedColor, dpi);
        }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
0
        private void Scan(ScanColor clr, int dpi)
        {
            //  Microsoft.Win32.RegistryKey jpegKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID\{D2923B86-15F1-46FF-A19A-DE825F919576}\SupportedExtension\.jpg");

            //string  jpegGuid = jpegKey.GetValue("FormatGUID") as string;

            CommonDialogClass commonDialogClass = new CommonDialogClass();
            Device            device            = commonDialogClass.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (device != null)
            {
                string           deviceID     = device.DeviceID;
                WIA.CommonDialog commonDialog = new CommonDialogClass();
                bool             flag         = true;
                int num  = 0;
                int num2 = 0;
                while (flag)
                {
                    DeviceManager deviceManager = new DeviceManagerClass();
                    Device        device2       = null;
                    foreach (DeviceInfo deviceInfo in deviceManager.DeviceInfos)
                    {
                        if (deviceInfo.DeviceID == deviceID)
                        {
                            WIA.Properties properties = deviceInfo.Properties;
                            device2 = deviceInfo.Connect();
                            break;
                        }
                    }
                    Item   item = device2.Items[1];
                    object obj  = (int)clr;
                    object obj2 = "6146";
                    setItem(item, obj2, obj);

                    object obj3 = dpi;
                    object obj4 = "6147";
                    setItem(item, obj4, obj3);
                    object obj5 = dpi;
                    object obj6 = "6148";

                    setItem(item, obj6, obj5);
                    try
                    {
                        ImageFile imageFile    = (ImageFile)commonDialog.ShowTransfer(item, "{00000000-0000-0000-0000-000000000000}", false);
                        string    tempFileName = Path.GetTempFileName();
                        if (File.Exists(tempFileName))
                        {
                            File.Delete(tempFileName);
                        }
                        imageFile.SaveFile(tempFileName);
                        Image img = Image.FromFile(tempFileName);


                        EventHandler <WiaImageEventArgs> scanning = this.Scanning;
                        if (scanning != null)
                        {
                            scanning(this, new WiaImageEventArgs(img));
                        }
                        num2++;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        Property property  = null;
                        Property property2 = null;
                        foreach (Property property3 in device2.Properties)
                        {
                            if ((long)property3.PropertyID == 3088L)
                            {
                                property = property3;
                            }
                            if ((long)property3.PropertyID == 3087L)
                            {
                                property2 = property3;
                            }
                        }
                        flag = false;
                        if (property != null)
                        {
                            if ((Convert.ToUInt32(property.get_Value()) & 1u) != 0u)
                            {
                                flag = ((Convert.ToUInt32(property2.get_Value()) & 1u) != 0u);
                            }
                        }
                        num++;
                    }
                }
                EventHandler scanComplete = this.ScanComplete;
                if (scanComplete != null)
                {
                    scanComplete(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 4
0
 public void BeginScan(ScanColor color, int dotsperinch)
 {
     this.Scan(color, dotsperinch);
 }
Ejemplo n.º 5
0
        private void btnAutoScan_Click(object sender, EventArgs e)
        {
            DeviceManager manager = new DeviceManagerClass();
            Device        device  = null;

            foreach (DeviceInfo info in manager.DeviceInfos)
            {
                if (info.Type != WiaDeviceType.ScannerDeviceType)
                {
                    continue;
                }
                device = info.Connect();
                break;
            }
            Item item = device.Items[1];
            //string s = "";
            //for (int i = 1; i < item.Properties.Count - 1; i++)
            //{
            //    object o = (int)i;
            //    Property p = item.Properties.get_Item(ref o);

            //    s += p.Name + "----" + p.PropertyID + "----" + Convert.ToString(p.get_Value()) + "\r\n";
            //}



            int       dpi   = (int)numericUpDown1.Value;
            ScanColor color = (ScanColor)this._colors[this.comboBox1.SelectedIndex];
            object    obj   = (int)color;
            object    obj2  = "6146";//WiaImageIntent

            setItem(item, obj2, obj);

            object obj3 = dpi;
            object obj4 = "6147";

            setItem(item, obj4, obj3);
            object obj5 = dpi;
            object obj6 = "6148";

            setItem(item, obj6, obj5);

            setItem(item, "6151", 800);
            setItem(item, "6152", 100 * 11);



            CommonDialogClass cdc       = new WIA.CommonDialogClass();
            ImageFile         imageFile = cdc.ShowTransfer(item,
                                                           "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}",
                                                           true) as ImageFile;

            if (imageFile != null)
            {
                var buffer = imageFile.FileData.get_BinaryData() as byte[];
                using (MemoryStream ms = new MemoryStream())
                {
                    ms.Write(buffer, 0, buffer.Length);
                    pictureBox1.Image = Image.FromStream(ms);
                }
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 public void BeginScan(ScanColor color, int dotsperinch, string deviceuuid, string iniPath)
 {
     Scan(color, dotsperinch, deviceuuid, iniPath);
 }
Ejemplo n.º 8
0
        void Scan(ScanColor clr, int dpi)
        {
            string deviceid;
            //Choose Scanner
            CommonDialog class1 = new CommonDialog();
            Device       d      = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (d != null)
            {
                deviceid = d.DeviceID;
            }
            else
            {
                //no scanner chosen
                return;
            }
            WIA.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)
                    {
                        WIA.Properties infoprop = null;
                        infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break;
                    }
                }
                //Start Scan
                WIA.ImageFile img  = null;
                WIA.Item      Item = WiaDev.Items[1] as WIA.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!
                    var testFormat = FormatID.wiaFormatJPEG;
                    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, testFormat, 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 = Image.FromFile(varImageFileName);
                    EventHandler <WiaImageEventArgs> temp = Scanning;
                    if (temp != null)
                    {
                        temp(this, new WiaImageEventArgs(ret));
                    }
                    numPages++;
                    img = null;
                }
                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);
            }
        }
Ejemplo n.º 9
0
        void Scan(ScanColor clr, int dpi)
        {
            string deviceid;
            //Choose Scanner
            CommonDialogClass class1 = new CommonDialogClass();
            Device d = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
            if (d != null)
            {
                deviceid = d.DeviceID;
            }
            else
            {
                //no scanner chosen
                return;
            }
            WIA.CommonDialog WiaCommonDialog = new CommonDialogClass();
            bool hasMorePages = true;
            int x = 0;
            int numPages = 0;
            while (hasMorePages)
            {
                //Create DeviceManager
                DeviceManager manager = new DeviceManagerClass();
                Device WiaDev = null;
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == deviceid)
                    {
                        WIA.Properties infoprop = null;
                        infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break;
                    }
                }
                //Start Scan
                WIA.ImageFile img = null;
                WIA.Item Item = WiaDev.Items[1] as WIA.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, 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 = Image.FromFile(varImageFileName);
                    EventHandler<WiaImageEventArgs> temp = Scanning;
                    if (temp != null)
                    {
                        temp(this, new WiaImageEventArgs(ret));
                    }
                    numPages++;
                    img = null;
                }
                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);
            }
        }
Ejemplo n.º 10
0
 public void BeginScan(ScanColor color, int dotsperinch)
 {
     Scan(color, dotsperinch);
 }
Ejemplo n.º 11
0
 public void BeginScan(string directory, ScanColor color, int dotsperinch)
 {
     Scan(directory, color, dotsperinch);
 }