コード例 #1
0
 private void SetDocumentToViewModel(Bitmap image)
 {
     if (_actionResult.Success)
     {
         _viewModel.ScannedImage = image;
         _actionResult.AddInfo("Document scanned.");
     }
     else
     {
         MessageHelper.Show(_actionResult);
     }
     ServiceLocator.Get <OperationScopeContext>().SetActionResultAsync(_actionResult);
 }
コード例 #2
0
        public Bitmap ScanDocument(bool showDevicesDialog, Scanner scanner, IActionResult actionResult)
        {
            Bitmap bitmap = null;

            WrapCOMError(() =>
            {
                ImageFile scannedImageFile;
                try
                {
                    const string bmpFormatID = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}";
                    if (scanner != null && scanner.Device != null)
                    {
                        scannedImageFile = CommonDialog.ShowTransfer(scanner.Device, bmpFormatID, true) as ImageFile;
                    }
                    else
                    {
                        scannedImageFile = CommonDialog.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.TextIntent,
                                                                         WiaImageBias.MaximizeQuality, bmpFormatID, showDevicesDialog, false, true) as ImageFile;
                    }
                    if (scannedImageFile == null)
                    {
                        actionResult.AddError("Scanning failed.");
                    }
                }
                catch (COMException e)
                {
                    const int operationCancelledErrorResult = -2145320860;
                    if (e.ErrorCode != operationCancelledErrorResult)
                    {
                        throw;
                    }
                    actionResult.AddInfo("Scanning canceled.");
                    return;
                }
                bitmap = SaveFile(scannedImageFile);
            });
            return(bitmap);
        }