Пример #1
0
        private async Task <(bool, string)> SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify)
        {
            if (images.Count == 0)
            {
                return(true, null);
            }
            string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i);

            if (settings.PromptForFilePath)
            {
                if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i);
                }
                else
                {
                    return(false, null);
                }
            }
            var extension = Path.GetExtension(subPath);

            if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                if (File.Exists(subPath))
                {
                    subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1);
                }
                var op = operationFactory.Create <SavePdfOperation>();
                if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, false, null))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.PdfSaved(subPath);
                }
                return(success, subPath);
            }
            else
            {
                var op = operationFactory.Create <SaveImagesOperation>();
                if (op.Start(subPath, now, images))
                {
                    operationProgress.ShowProgress(op);
                }
                bool success = await op.Success;
                if (success)
                {
                    notify?.ImagesSaved(images.Count, op.FirstFileSaved);
                }
                return(success, subPath);
            }
        }
Пример #2
0
        public async Task <bool> ExportPDF(string filename, List <ScannedImage> images, bool email, EmailMessage emailMessage)
        {
            var op = operationFactory.Create <SavePdfOperation>();

            var pdfSettings = pdfSettingsContainer.PdfSettings;

            pdfSettings.Metadata.Creator = MiscResources.NAPS2;
            if (op.Start(filename, DateTime.Now, images, pdfSettings, ocrManager.DefaultParams, email, emailMessage))
            {
                operationProgress.ShowProgress(op);
            }
            return(await op.Success);
        }
Пример #3
0
 public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber)
 {
     if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan)
     {
         if (profile.Brightness != 0)
         {
             AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform {
                 Brightness = profile.Brightness
             });
         }
         if (profile.Contrast != 0)
         {
             AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform {
                 Contrast = profile.Contrast
             });
         }
     }
     if (profile.FlipDuplexedPages && pageNumber % 2 == 0)
     {
         AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone));
     }
     if (profile.AutoDeskew)
     {
         var op = operationFactory.Create <DeskewOperation>();
         if (op.Start(new[] { image }))
         {
             operationProgress.ShowProgress(op);
         }
     }
     if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None)
     {
         image.PatchCode = PatchCodeDetector.Detect(bitmap);
     }
 }
Пример #4
0
        private async void tsDeskew_Click(object sender, EventArgs e)
        {
            var op = operationFactory.Create <DeskewOperation>();

            if (op.Start(new[] { ImageList.Images[ImageIndex] }))
            {
                operationProgress.ShowProgress(op);
                await UpdateImage();
            }
        }
Пример #5
0
 public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber, bool supportsNativeUI = true)
 {
     if (!scanParams.NoThumbnails)
     {
         image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap));
     }
     if (scanParams.SkipPostProcessing)
     {
         return;
     }
     if (profile.StretchHistogram && !profile.HistogramStretchConfig.IsNull)
     {
         AddTransformAndUpdateThumbnail(image, ref bitmap, new StretchHistogramTransform {
             Parameters = profile.HistogramStretchConfig
         });
     }
     if ((!profile.UseNativeUI || !supportsNativeUI) && profile.BrightnessContrastAfterScan)
     {
         if (profile.Brightness != 0)
         {
             AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform {
                 Brightness = profile.Brightness
             });
         }
         if (profile.Contrast != 0)
         {
             AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform {
                 Contrast = profile.Contrast
             });
         }
     }
     if (profile.FlipDuplexedPages && pageNumber % 2 == 0)
     {
         AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone));
     }
     if (profile.AutoDeskew)
     {
         var op = operationFactory.Create <DeskewOperation>();
         if (op.Start(new[] { image }))
         {
             operationProgress.ShowProgress(op);
             op.Wait();
         }
     }
     if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None)
     {
         image.PatchCode = PatchCodeDetector.Detect(bitmap);
     }
 }
Пример #6
0
        public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber)
        {
            if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan)
            {
                if (profile.Brightness != 0)
                {
                    AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform {
                        Brightness = profile.Brightness
                    });
                }
                if (profile.Contrast != 0)
                {
                    AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform {
                        Contrast = profile.Contrast
                    });
                }
            }
            if (profile.FlipDuplexedPages && pageNumber % 2 == 0)
            {
                AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone));
            }
            if (profile.AutoDeskew)
            {
                var op = operationFactory.Create <DeskewOperation>();
                if (op.Start(new[] { image }))
                {
                    operationProgress.ShowProgress(op);
                }
            }
            if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None)
            {
                IBarcodeReader reader        = new BarcodeReader();
                var            barcodeResult = reader.Decode(bitmap);
                if (barcodeResult != null)
                {
                    switch (barcodeResult.Text)
                    {
                    case "PATCH1":
                        image.PatchCode = PatchCode.Patch1;
                        break;

                    case "PATCH2":
                        image.PatchCode = PatchCode.Patch2;
                        break;

                    case "PATCH3":
                        image.PatchCode = PatchCode.Patch3;
                        break;

                    case "PATCH4":
                        image.PatchCode = PatchCode.Patch4;
                        break;

                    case "PATCH6":
                        image.PatchCode = PatchCode.Patch6;
                        break;

                    case "PATCHT":
                        image.PatchCode = PatchCode.PatchT;
                        break;
                    }
                }
            }
        }
Пример #7
0
        public void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber)
        {
            if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan)
            {
                if (profile.Brightness != 0)
                {
                    AddTransformAndUpdateThumbnail(image, ref bitmap, new BrightnessTransform {
                        Brightness = profile.Brightness
                    });
                }
                if (profile.Contrast != 0)
                {
                    AddTransformAndUpdateThumbnail(image, ref bitmap, new TrueContrastTransform {
                        Contrast = profile.Contrast
                    });
                }
            }
            if (profile.FlipDuplexedPages && pageNumber % 2 == 0)
            {
                AddTransformAndUpdateThumbnail(image, ref bitmap, new RotationTransform(RotateFlipType.Rotate180FlipNone));
            }
            if (profile.AutoDeskew)
            {
                var op = operationFactory.Create <DeskewOperation>();
                if (op.Start(new[] { image }))
                {
                    operationProgress.ShowProgress(op);
                }
            }
            if (scanParams.DetectPatchCodes && image.PatchCode == PatchCode.None)
            {
                IBarcodeReader reader        = new BarcodeReader();
                var            barcodeResult = reader.Decode(bitmap);
                if (barcodeResult != null)
                {
                    switch (barcodeResult.Text)
                    {
                    case "PATCH1":
                        image.PatchCode = PatchCode.Patch1;
                        break;

                    case "PATCH2":
                        image.PatchCode = PatchCode.Patch2;
                        break;

                    case "PATCH3":
                        image.PatchCode = PatchCode.Patch3;
                        break;

                    case "PATCH4":
                        image.PatchCode = PatchCode.Patch4;
                        break;

                    case "PATCH6":
                        image.PatchCode = PatchCode.Patch6;
                        break;

                    case "PATCHT":
                        image.PatchCode = PatchCode.PatchT;
                        break;
                    }
                }
            }
            else if (scanParams.DetectBarcodes)
            {
                IMultipleBarcodeReader multiReader = new BarcodeReader();
                multiReader.Options.TryHarder = true;
                // profile.AutoSaveSettings.Separator == ImportExport.SaveSeparator.Barcode
                if (profile.AutoSaveSettings != null)
                {
                    if (profile.AutoSaveSettings.BarcodeType != null && profile.AutoSaveSettings.BarcodeType != "")
                    {
                        switch (profile.AutoSaveSettings.BarcodeType)
                        {
                        case "2of5 interleaved":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.ITF);
                            break;

                        case "Code 39":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_39);
                            break;

                        case "Code 93":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_93);
                            break;

                        case "Code 128":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.CODE_128);
                            break;

                        case "EAN 8":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_8);
                            break;

                        case "EAN13":
                            multiReader.Options.PossibleFormats = new List <BarcodeFormat>();
                            multiReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);
                            break;
                        }
                    }
                }

                var barcodeResult = multiReader.DecodeMultiple(bitmap);
                if (barcodeResult != null)
                {
                    foreach (var barcode in barcodeResult)
                    {
                        image.Barcode = barcode.Text;
                        System.Diagnostics.Debug.WriteLine(barcode.BarcodeFormat + " = " + barcode.Text);
                    }
                }
            }
        }