Beispiel #1
0
        public async Task <IEnumerable <StorageFile> > ScanPicturesAsync(
            String scannerDeviceId, ImageScannerScanSource source,
            StorageFolder destinationFolder,
            Double hScanPercent, Double vScanPercent)
        {
            var scanner = await ImageScanner.FromIdAsync(scannerDeviceId);

            if (scanner.IsScanSourceSupported(source))
            {
                ConfigureScanner(scanner, source, hScanPercent, vScanPercent);

                var scanResult = await scanner
                                 .ScanFilesToFolderAsync(source, destinationFolder);

                var results = new List <StorageFile>();
                // Caution - enumerating this list (foreach) will result in a
                // COM exception.  Instead, just walk the collection by index
                // and build a new list.
                for (var i = 0; i < scanResult.ScannedFiles.Count; i++)
                {
                    results.Add(scanResult.ScannedFiles[i]);
                }
                return(results);
            }
            return(null);
        }
Beispiel #2
0
        public async Task <BitmapImage> ScanPicturePreviewAsync
            (String scannerDeviceId, ImageScannerScanSource scanSource)
        {
            var scanner = await ImageScanner.FromIdAsync(scannerDeviceId);

            if (scanner.IsPreviewSupported(scanSource))
            {
                var stream = new InMemoryRandomAccessStream();
                var result =
                    await scanner.ScanPreviewToStreamAsync(scanSource, stream);

                if (result.Succeeded)
                {
                    var thumbnail = new BitmapImage();
                    thumbnail.SetSource(stream);
                    return(thumbnail);
                }
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Gets all available Image Formats for a Scan Source
        /// </summary>
        /// <param name="scanner"></param>
        /// <param name="source"></param>
        /// <returns>List with all available ImageScannerFormats for the given source</returns>
        public static List <ImageScannerFormat> GetSupportedImageFormats(ImageScanner scanner, ImageScannerScanSource source)
        {
            List <ImageScannerFormat> availableFormats = new List <ImageScannerFormat>();

            switch (source)
            {
            case ImageScannerScanSource.Flatbed:     // Flatbed
            {
                foreach (ImageScannerFormat format in (ImageScannerFormat[])Enum.GetValues(typeof(ImageScannerFormat)))
                {
                    if (scanner.FlatbedConfiguration.IsFormatSupported(format))
                    {
                        availableFormats.Add(format);
                    }
                }
                break;
            }

            case ImageScannerScanSource.Feeder:     // Feeder
            {
                foreach (ImageScannerFormat format in (ImageScannerFormat[])Enum.GetValues(typeof(ImageScannerFormat)))
                {
                    if (scanner.FeederConfiguration.IsFormatSupported(format))
                    {
                        availableFormats.Add(format);
                    }
                }
                break;
            }

            case ImageScannerScanSource.AutoConfigured:     // Auto Configured
            {
                foreach (ImageScannerFormat format in (ImageScannerFormat[])Enum.GetValues(typeof(ImageScannerFormat)))
                {
                    if (scanner.AutoConfiguration.IsFormatSupported(format))
                    {
                        availableFormats.Add(format);
                    }
                }
                break;
            }

            case ImageScannerScanSource.Default:        // Catch the otherwise empty set by only providing Bitmap as option, as this is device independant
            {
                availableFormats.Add(ImageScannerFormat.DeviceIndependentBitmap);
                break;
            }
            }

            return(availableFormats);
        }
Beispiel #4
0
        /// <summary>
        /// Gets all available Colour Modes for a Scan Source
        /// </summary>
        /// <param name="scanner"></param>
        /// <param name="source"></param>
        /// <returns>List with all available ImageScannerColorMode for the given source</returns>
        public static List <ImageScannerAutoCroppingMode> GetSupportedAutoCroppingModes(ImageScanner scanner, ImageScannerScanSource source)
        {
            List <ImageScannerAutoCroppingMode> availableAutoCroppingModes = new List <ImageScannerAutoCroppingMode>();

            switch (source)
            {
            case ImageScannerScanSource.Flatbed:     // Flatbed
            {
                foreach (ImageScannerAutoCroppingMode autoCroppingMode in (ImageScannerAutoCroppingMode[])Enum.GetValues(typeof(ImageScannerAutoCroppingMode)))
                {
                    if (scanner.FlatbedConfiguration.IsAutoCroppingModeSupported(autoCroppingMode))
                    {
                        availableAutoCroppingModes.Add(autoCroppingMode);
                    }
                }
                break;
            }

            case ImageScannerScanSource.Feeder:     // Feeder
            {
                foreach (ImageScannerAutoCroppingMode autoCroppingMode in (ImageScannerAutoCroppingMode[])Enum.GetValues(typeof(ImageScannerAutoCroppingMode)))
                {
                    if (scanner.FeederConfiguration.IsAutoCroppingModeSupported(autoCroppingMode))
                    {
                        availableAutoCroppingModes.Add(autoCroppingMode);
                    }
                }
                break;
            }

            case ImageScannerScanSource.AutoConfigured:     // Auto Configured
            {
                // Not possible, return empty List
                break;
            }

            case ImageScannerScanSource.Default:        // Catch the otherwise empty set by only providing Bitmap as option, as this is device independant
            {
                // Not possible, return empty List
                break;
            }
            }

            return(availableAutoCroppingModes);
        }
Beispiel #5
0
        private static void ConfigureScanner(
            ImageScanner scanner, ImageScannerScanSource source,
            Double hScanPercent, Double vScanPercent)
        {
            if (scanner == null)
            {
                throw new ArgumentNullException("scanner");
            }

            IImageScannerSourceConfiguration sourceConfig = null;
            IImageScannerFormatConfiguration formatConfig = null;

            switch (source)
            {
            case ImageScannerScanSource.Flatbed:
                sourceConfig = scanner.FlatbedConfiguration;
                formatConfig = scanner.FlatbedConfiguration;
                break;

            case ImageScannerScanSource.Feeder:
                sourceConfig = scanner.FeederConfiguration;
                formatConfig = scanner.FeederConfiguration;
                //Additional feeder-specific settings:
                //scanner.FeederConfiguration.CanScanDuplex
                //scanner.FeederConfiguration.Duplex
                //scanner.FeederConfiguration.CanScanAhead
                //scanner.FeederConfiguration.ScanAhead
                //scanner.FeederConfiguration.AutoDetectPageSize
                //scanner.FeederConfiguration.CanAutoDetectPageSize
                //scanner.FeederConfiguration.PageSize
                //scanner.FeederConfiguration.PageSizeDimensions
                //scanner.FeederConfiguration.PageOrientation
                break;

            case ImageScannerScanSource.AutoConfigured:
                formatConfig = scanner.AutoConfiguration;
                break;
            }

            // Potentially update the scanner configuration
            if (sourceConfig != null)
            {
                var maxScanArea = sourceConfig.MaxScanArea; // Size, with Width, Height in Inches    // MinScanArea
                sourceConfig.SelectedScanRegion = new Rect(
                    0,
                    0,
                    maxScanArea.Width * hScanPercent,
                    maxScanArea.Height * vScanPercent); // In inches
                // Additional Configuration settings
                // sourceConfig.AutoCroppingMode
                // sourceConfig.ColorMode ==     // DefaultColorMode
                // sourceConfig.Brightness   // DefaultBrightness    //MaxBrightness     // MinBrightness
                // sourceConfig.Contrast     // DefaultContrast      // MaxContrast      // MinContrast
                // sourceConfig.DesiredResolution = resolution;      // MaxResolution    // MinResolution
                // var actualResolution = sourceConfig.ActualResolution;
            }

            // Potentially update the format that the end product is saved to
            if (formatConfig != null)
            {
                Debug.WriteLine("Default format is {0}", formatConfig.DefaultFormat);

                // NOTE: If your desired format isn't natively supported, it may
                // be possible to generate the desired format post-process
                // using image conversion, etc. libraries.
                var desiredFormats = new[]
                {
                    ImageScannerFormat.Png,
                    ImageScannerFormat.Jpeg,
                    ImageScannerFormat.DeviceIndependentBitmap,
                    //ImageScannerFormat.Tiff,
                    //ImageScannerFormat.Xps,
                    //ImageScannerFormat.OpenXps,
                    //ImageScannerFormat.Pdf
                };

                foreach (var format in desiredFormats)
                {
                    if (formatConfig.IsFormatSupported(format))
                    {
                        formatConfig.Format = format;
                        break;
                    }
                }

                Debug.WriteLine("Configured format is {0}", formatConfig.Format);
            }
        }
Beispiel #6
0
 private void cmbxScannerSource_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     selectedScannerSource = (ImageScannerScanSource)cmbxScannerSource.SelectedItem;
     GetAllAvailableSettingsForCurrentScannerSource();
 }