Пример #1
0
 public WiaConfiguration Wia10NativeUi(string deviceId, IntPtr hwnd)
 {
     try
     {
         try
         {
             using (var deviceManager = new WiaDeviceManager(WiaVersion.Wia10))
                 using (var device = deviceManager.FindDevice(deviceId))
                 {
                     var item = device.PromptToConfigure(hwnd);
                     return(new WiaConfiguration
                     {
                         DeviceProps = device.Properties.SerializeEditable(),
                         ItemProps = item.Properties.SerializeEditable(),
                         ItemName = item.Name()
                     });
                 }
         }
         catch (WiaException e)
         {
             WiaScanErrors.ThrowDeviceError(e);
             throw new InvalidOperationException();
         }
     }
     catch (ScanDriverException e)
     {
         throw new FaultException <ScanDriverExceptionDetail>(new ScanDriverExceptionDetail(e));
     }
 }
Пример #2
0
 protected override List <ScanDevice> GetDeviceListInternal()
 {
     using (var deviceManager = new WiaDeviceManager(ScanProfile.WiaVersion))
     {
         return(deviceManager.GetDeviceInfos().Select(deviceInfo =>
         {
             using (deviceInfo)
             {
                 return new ScanDevice(deviceInfo.Id(), deviceInfo.Name());
             }
         }).ToList());
     }
 }
Пример #3
0
        private void DoWia20NativeTransfer(ScannedImageSource.Concrete source, WiaDeviceManager deviceManager, WiaDevice device)
        {
            // WIA 2.0 doesn't support normal transfers with native UI.
            // Instead we need to have it write the scans to a set of files and load those.
            if (DialogParent == null)
            {
                DialogParent = new BackgroundForm();
            }
            var hwnd  = Invoker.Current.InvokeGet(() => DialogParent.Handle);
            var paths = deviceManager.PromptForImage(hwnd, device);

            if (paths == null)
            {
                return;
            }

            int pageNumber = 1;

            InitProgress(device);

            try
            {
                foreach (var path in paths)
                {
                    using (var stream = new FileStream(path, FileMode.Open))
                        using (var output = Image.FromStream(stream))
                        {
                            int frameCount = output.GetFrameCount(FrameDimension.Page);
                            for (int i = 0; i < frameCount; i++)
                            {
                                output.SelectActiveFrame(FrameDimension.Page, i);
                                ProduceImage(source, output, ref pageNumber);
                            }
                        }
                }
            }
            finally
            {
                foreach (var path in paths)
                {
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception e)
                    {
                        Log.ErrorException("Error deleting WIA 2.0 native transferred file", e);
                    }
                }
            }
        }
Пример #4
0
        private void Scan(ScannedImageSource.Concrete source)
        {
            using (var deviceManager = new WiaDeviceManager(ScanProfile.WiaVersion))
                using (var device = deviceManager.FindDevice(ScanProfile.Device.ID))
                {
                    if (device.Version == WiaVersion.Wia20 && ScanProfile.UseNativeUI)
                    {
                        DoWia20NativeTransfer(source, deviceManager, device);
                        return;
                    }

                    using (var item = GetItem(device))
                    {
                        if (item == null)
                        {
                            return;
                        }

                        DoTransfer(source, device, item);
                    }
                }
        }
Пример #5
0
        protected override ScanDevice PromptForDeviceInternal()
        {
            try
            {
                using (var deviceManager = new WiaDeviceManager(ScanProfile.WiaVersion))
                {
                    using (var device = deviceManager.PromptForDevice(DialogParent?.Handle ?? IntPtr.Zero))
                    {
                        if (device == null)
                        {
                            return(null);
                        }

                        return(new ScanDevice(device.Id(), device.Name()));
                    }
                }
            }
            catch (WiaException e) when(e.ErrorCode == WiaErrorCodes.NO_DEVICE_AVAILABLE)
            {
                throw new NoDevicesFoundException();
            }
        }