Exemple #1
0
        private Device CreateDeviceManager()
        {
            DeviceManager manager = new DeviceManagerClass();
            Device        wiaDev  = null;

            foreach (DeviceInfo info in manager.DeviceInfos)
            {
                if (info.DeviceID == m_DeviceID)
                {
                    WIA.Properties infoprop = null;
                    infoprop = info.Properties;

                    //connect to scanner
                    try
                    {
                        Thread.Sleep(500);
                        wiaDev = info.Connect();
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(500);
                        //throw;
                    }

                    break;
                }
            }
            return(wiaDev);
        }
 public static void ShowPropertiesDialog(WIA.Properties properties)
 {
     using (PropertiesDialog dialog = new PropertiesDialog(properties))
     {
         dialog.ShowDialog();
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="searchBag"></param>
 /// <param name="propID"></param>
 /// <param name="propValue"></param>
 public static void SetProperty(this WIA.Properties searchBag, int propID, object propValue)
 {
     foreach (Property prop in searchBag.Cast <Property>().Where(prop => prop.PropertyID == propID))
     {
         prop.set_Value(ref propValue);
         return;
     }
 }
Exemple #4
0
 public static object GetProperty(this WIA.Properties searchBag, int propID)
 {
     foreach (Property prop in searchBag)
     {
         if (prop.PropertyID == propID)
         {
             return(prop.get_Value());
         }
     }
     return(null);
 }
Exemple #5
0
 public static void SetProperty(this WIA.Properties searchBag, int propID, object propValue)
 {
     foreach (Property prop in searchBag)
     {
         if (prop.PropertyID == propID)
         {
             prop.set_Value(ref propValue);
             return;
         }
     }
 }
 private static Property FindProperty(WIA.Properties properties, WiaProperty property)
 {
     foreach (Property prop in properties)
     {
         if (prop.PropertyID == (int)property)
         {
             return(prop);
         }
     }
     return(null);
 }
Exemple #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="propriedades"></param>
 /// <param name="idPropriedade"></param>
 /// <returns></returns>
 private static Property PesquisaPropriedade(WIA.Properties propriedades, int idPropriedade)
 {
     foreach (Property property in propriedades)
     {
         if (property.PropertyID == idPropriedade)
         {
             return(property);
         }
     }
     return(null);
 }
Exemple #8
0
 protected internal dynamic GetPropertyValue(WIA.Properties props, string propertyName)
 {
     foreach (IProperty property in props)
     {
         if (property.Name == propertyName)
         {
             return(property.get_Value());
         }
     }
     return(null);
 }
 public static Property FindProperty(WIA.Properties properties, int propertyId)
 {
     foreach (Property property in properties)
     {
         if (property.PropertyID == propertyId)
         {
             return(property);
         }
     }
     return(null);
 }
Exemple #10
0
 private Property FindProperty(WIA.Properties properties, WiaProperty property)
 {
     Log("Try to find property: " + property);
     foreach (Property prop in properties)
     {
         if (prop.PropertyID == (int)property)
         {
             Log(string.Format("Property '{0}' was found", property));
             return(prop);
         }
     }
     Log(string.Format("Property '{0}' was not found", property));
     return(null);
 }
Exemple #11
0
        private void SaveProp(WIA.Properties props, ref Dictionary <string, object> dic)
        {
            if (dic == null)
            {
                dic = new Dictionary <string, object>();
            }

            foreach (Property property in props)
            {
                var propId    = property.PropertyID.ToString();
                var propValue = property.get_Value();

                dic[propId] = propValue;
            }
        }
Exemple #12
0
        public ADFScan(string deviceID)
        {
            _deviceID = deviceID;
            DeviceManager manager = new DeviceManagerClass();

            foreach (DeviceInfo info in manager.DeviceInfos)
            {
                if (info.DeviceID == _deviceID)
                {
                    WIA.Properties infoprop = null;
                    infoprop = info.Properties;
                    //connect to scanner
                    _WiaDev = info.Connect();
                    break;
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Connect to Scanning Device
        /// </summary>
        /// <param name="deviceID"></param>
        /// <returns></returns>
        private Device Connect()
        {
            Device WiaDev = null;

            DeviceManager manager = new DeviceManager();

            //Iterate through each Device until correct Device found
            foreach (DeviceInfo info in manager.DeviceInfos)
            {
                if (info.DeviceID == DeviceID)
                {
                    WIA.Properties infoprop = info.Properties;

                    WiaDev = info.Connect();
                    return(WiaDev);
                }
            }

            throw new Exception("Scanner not found - Is it setup in DeviceID?");
        }
Exemple #14
0
        private void WritePropertiesToFile(WIA.Properties properties)
        {
            foreach (Property prop in properties)
            {
                var name = prop.Name;
                var val  = prop.get_Value();
                int?min  = null;
                int?max  = null;
                try
                {
                    min = prop.SubTypeMin;
                    max = prop.SubTypeMax;
                }
                catch (Exception)
                {
                }

                File.AppendAllText(
                    "info2.txt",
                    string.Format("id: {4}, name: {0}, val: {1}, min: {2}, max: {3}\r\n", name, val, min.HasValue ? min.Value.ToString() : "", max.HasValue ? max.Value.ToString() : "", prop.PropertyID));
            }
        }
Exemple #15
0
        /// <summary>
        /// Connect to Scanning Device
        /// </summary>
        /// <param name="deviceID"></param>
        /// <returns></returns>
        private Device Connect()
        {
            try
            {
                Device WiaDev = null;

                DeviceManager manager = new DeviceManager();

                //Iterate through each Device until correct Device found
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == DeviceID)
                    {
                        WIA.Properties infoprop = info.Properties;

                        WiaDev = info.Connect();
                        return(WiaDev);
                    }
                }
            }
            catch (Exception ex)
            { }
            return(null);
        }
        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);
                }
            }
        }
 public PropertiesDialog(WIA.Properties properties)
     : this()
 {
     _properties = properties;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="searchBag"></param>
 /// <param name="propID"></param>
 /// <returns></returns>
 public static object GetProperty(this WIA.Properties searchBag, int propID)
 {
     return((from Property prop in searchBag where prop.PropertyID == propID select prop.get_Value()).FirstOrDefault <object>());
 }
Exemple #19
0
        public ArrayList ADFScan()
        {
            ArrayList dataArray = new ArrayList();

            //Choose Scanner
            CommonDialogClass class1 = new CommonDialogClass();
            //

            //class1.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);
            //
            Device d = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (d != null)
            {
                this.DeviceID = d.DeviceID;
            }
            else
            {
                //no scanner chosen
                return(new ArrayList());
            }



            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 == this.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;

                try
                {
                    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, wiaFormatJPEG, false);


                    //process image:
                    //one would do image processing here
                    //
                    dataArray.Add(img);
                    //Save to file
                    //string varImageFileName = "c:\\test" + x.ToString() + ".jpg";
                    // if (File.Exists(varImageFileName))
                    // {
                    //     //file exists, delete it
                    //     File.Delete(varImageFileName);
                    // }
                    // img.SaveFile(varImageFileName);
                    numPages++;
                    img = null;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
                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++;
                }
            }
            return(dataArray);
        }
        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);
            }
        }
Exemple #21
0
        private void DoScan()
        {
            WIA.Item         item            = default(WIA.Item);
            WIA.ImageFile    Img             = default(WIA.ImageFile);
            WIA.CommonDialog WiaCommonDialog = new CommonDialogClass();
            bool             hasMorePages    = true;
            int    x           = 0;
            int    numPages    = 0;
            string ImgMain     = null;
            string ImgMainName = null;

            try
            {
                if (treealfresco.SelectedNode == null)
                {
                    MessageBox.Show("Please select a Space to store your data into", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ResultSetRowNode node = (ResultSetRowNode)treealfresco.SelectedNode.Tag;
                LocationUuid = node.id;

                LocationName = treealfresco.SelectedNode.Text;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            while (hasMorePages)
            {
                //Create DeviceManager
                DeviceManager manager = new DeviceManagerClass();
                Device        WiaDev  = null;
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == this.DeviceID)
                    {
                        WIA.Properties infoprop = null;
                        infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

                //Start Scan

                Img = null;

                item = WiaDev.Items[1] as WIA.Item;

                try
                {
                    Img = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatTIFF, false);

                    //process image:
                    //one would do image processing here

                    //Save to file
                    string jpegGuid = null;
                    //retrieves jpegKey from registry, used in saving JPEG
                    Microsoft.Win32.RegistryKey jpegKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\\{D2923B86-15F1-46FF-A19A-DE825F919576}\\SupportedExtension\\.jpg");
                    jpegGuid = (string)jpegKey.GetValue("FormatGUID");
                    //loops through available formats for the captured item, looking for the JPG format
                    foreach (string format in item.Formats)
                    {
                        if ((format == jpegGuid))
                        {
                            //transfers image to an imagefile object
                            Img = (WIA.ImageFile)item.Transfer(WIA.FormatID.wiaFormatTIFF);
                            int Counter = 0;
                            //counter in loop appended to filename
                            bool LoopAgain = true;
                            //searches directory, gets next available picture name
                            while (!(LoopAgain == false))
                            {
                                string File = SavePath + "\\";
                                File += txtPrefix.Text;
                                File += Counter;
                                File += ".tiff";
                                string Filename = txtPrefix.Text;
                                Filename += Counter;
                                Filename += ".tiff";


                                if (System.IO.File.Exists(Filename))
                                {
                                    //file exists, delete it
                                    System.IO.File.Delete(Filename);
                                }
                                if (numPages == 0)
                                {
                                    Img.SaveFile(Filename);
                                }
                                ImgMain     = File;
                                ImgMainName = Filename;
                                if (numPages > 0)
                                {
                                    int y = Counter;
                                    y            = Counter - 1;
                                    ImgMain      = SavePath + "\\";
                                    ImgMain     += txtPrefix.Text;
                                    ImgMain     += y;
                                    ImgMain     += ".tiff";
                                    ImgMainName  = txtPrefix.Text;
                                    ImgMainName += y;
                                    ImgMainName += ".tiff";
                                    //createtiff(ImgMain, File);
                                }
                                numPages += 1;

                                Counter = Counter + 1;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
                finally
                {
                    item = null;
                    //determine if there are any more pages waiting
                    WIA.Property documentHandlingSelect = null;
                    WIA.Property documentHandlingStatus = null;
                    foreach (WIA.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;
                    UploadNow(ImgMainName, ImgMain);
                    MessageBox.Show(ImgMain + " uploaded");
                    //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 += 1;
                }
            }
        }