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); } }
public IEnumerable <int> MoveDown(IEnumerable <int> selection) { lock (this) { var newSelection = new int[selection.Count()]; int upperBound = Images.Count - 1; int j = 0; foreach (int i in selection.OrderByDescending(x => x)) { if (i != upperBound--) { ScannedImage img = Images[i]; Images.RemoveAt(i); Images.Insert(i + 1, img); img.MovedTo(i + 1); newSelection[j++] = i + 1; } else { newSelection[j++] = i; } } return(newSelection); } }
public IEnumerable <int> MoveUp(IEnumerable <int> selection) { lock (this) { var newSelection = new int[selection.Count()]; int lowerBound = 0; int j = 0; foreach (int i in selection.OrderBy(x => x)) { if (i != lowerBound++) { ScannedImage img = Images[i]; Images.RemoveAt(i); Images.Insert(i - 1, img); img.MovedTo(i - 1); newSelection[j++] = i - 1; } else { newSelection[j++] = i; } } return(newSelection); } }
public Bitmap this[ScannedImage scannedImage] { get { var newState = scannedImage.GetThumbnailState(); if (cache.ContainsKey(scannedImage)) { // Cache hit var item = cache[scannedImage]; if (item.State != newState) { // Invalidated item.Thumbnail.Dispose(); item.Thumbnail = scannedImage.GetThumbnail(thumbnailRenderer); item.State = newState; } return(item.Thumbnail); } else { // Cache miss var item = new CacheItem { Thumbnail = scannedImage.GetThumbnail(thumbnailRenderer), State = newState }; return(item.Thumbnail); } } }
public Task <Bitmap> RenderThumbnail(ScannedImage scannedImage, int size) { using (var snapshot = scannedImage.Preserve()) { return(RenderThumbnail(snapshot, size)); } }
public IEnumerable <int> MoveTo(IEnumerable <int> selection, int index) { var selList = selection.ToList(); var bottom = selList.Where(x => x < index).OrderByDescending(x => x).ToList(); var top = selList.Where(x => x >= index).OrderBy(x => x).ToList(); int offset = 1; foreach (int i in bottom) { ScannedImage img = Images[i]; Images.RemoveAt(i); Images.Insert(index - offset, img); img.MovedTo(index - offset); offset++; } offset = 0; foreach (int i in top) { ScannedImage img = Images[i]; Images.RemoveAt(i); Images.Insert(index + offset, img); img.MovedTo(index + offset); offset++; } return(Enumerable.Range(index - bottom.Count, selList.Count)); }
public async Task <Bitmap> Render(ScannedImage image, int outputSize = 0) { using (var snapshot = image.Preserve()) { return(await Render(snapshot, outputSize)); } }
public Bitmap this[ScannedImage scannedImage] { get { var newState = scannedImage.GetThumbnailState(); if (cache.ContainsKey(scannedImage)) { // Cache hit var item = cache[scannedImage]; if (item.State != newState) { // Invalidated item.Thumbnail.Dispose(); item.Thumbnail = scannedImage.GetThumbnail(userConfigManager.Config.ThumbnailSize); item.State = newState; } return item.Thumbnail; } else { // Cache miss var item = new CacheItem { Thumbnail = scannedImage.GetThumbnail(userConfigManager.Config.ThumbnailSize), State = newState }; return item.Thumbnail; } } }
public IEnumerable<ScannedImage> Import(string filePath, Func<int, int, bool> progressCallback) { if (!progressCallback(0, 1)) { yield break; } Bitmap toImport; try { toImport = new Bitmap(filePath); } catch (Exception e) { Log.ErrorException("Error importing image: " + filePath, e); // Handle and notify the user outside the method so that errors importing multiple files can be aggregated throw; } using (toImport) { int frameCount = toImport.GetFrameCount(FrameDimension.Page); for (int i = 0; i < frameCount; ++i) { if (!progressCallback(i, frameCount)) { yield break; } toImport.SelectActiveFrame(FrameDimension.Page, i); var image = new ScannedImage(toImport, ScanBitDepth.C24Bit, IsLossless(toImport.RawFormat), -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(toImport)); yield return image; } progressCallback(frameCount, frameCount); } }
public async Task <Stream> RenderToStream(ScannedImage image) { using (var snapshot = image.Preserve()) { return(await RenderToStream(snapshot)); } }
public Stream RenderToStream(ScannedImage image) { using (var transformed = Render(image)) { var stream = new MemoryStream(); transformed.Save(stream, image.FileFormat ?? (image.RecoveryIndexImage.HighQuality ? ImageFormat.Png : ImageFormat.Jpeg)); return(stream); } }
public static void PostProcessStep2(ScannedImage image, Bitmap bitmap, ScanProfile profile, ScanParams scanParams, int pageNumber) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } 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; } } } }
private static void AddTransformAndUpdateThumbnail(ScannedImage image, Transform transform) { image.AddTransform(transform); var thumbnail = image.GetThumbnail(null); if (thumbnail != null) { image.SetThumbnail(transform.Perform(thumbnail)); } }
private void AddTransformAndUpdateThumbnail(ScannedImage image, ref Bitmap bitmap, Transform transform) { image.AddTransform(transform); var thumbnail = image.GetThumbnail(null); if (thumbnail != null) { bitmap = transform.Perform(bitmap); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); } }
public Bitmap Render(ScannedImage image) { var bitmap = image.FileFormat == null ? pdfRenderer.Render(image.RecoveryFilePath).Single() : new Bitmap(image.RecoveryFilePath); lock (image.RecoveryIndexImage.TransformList) { return(Transform.PerformAll(bitmap, image.RecoveryIndexImage.TransformList)); } }
internal Snapshot(ScannedImage source) { lock (source) { if (source.disposed) { throw new ObjectDisposedException("source"); } source.snapshotCount++; Source = source; TransformList = source.transformList.ToList(); TransformState = source.transformState; } }
public bool Start(DirectImageTransfer data, bool copy, Action<ScannedImage> imageCallback) { ProgressTitle = copy ? MiscResources.CopyProgress : MiscResources.ImportProgress; Status = new OperationStatus { StatusText = copy ? MiscResources.Copying : MiscResources.Importing, MaxProgress = data.ImageRecovery.Length }; cancel = false; thread = threadFactory.StartThread(() => { Exception error = null; foreach (var ir in data.ImageRecovery) { try { ScannedImage img; using (var bitmap = new Bitmap(Path.Combine(data.RecoveryFolder, ir.FileName))) { img = new ScannedImage(bitmap, ir.BitDepth, ir.HighQuality, -1); } foreach (var transform in ir.TransformList) { img.AddTransform(transform); } img.SetThumbnail(thumbnailRenderer.RenderThumbnail(img)); imageCallback(img); Status.CurrentProgress++; InvokeStatusChanged(); if (cancel) { break; } } catch (Exception ex) { error = ex; } } if (error != null) { Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, data.RecoveryFolder), error); } Status.Success = true; InvokeFinished(); }); return true; }
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); } }
public void RunBackgroundOcr(ScannedImage image, ScanParams scanParams, string tempPath) { if (ShouldDoBackgroundOcr(scanParams)) { using (var snapshot = image.Preserve()) { if (scanParams.DoOcr == true) { ocrRequestQueue.QueueForeground(null, snapshot, tempPath, scanParams.OcrParams, scanParams.OcrCancelToken).AssertNoAwait(); } else { ocrRequestQueue.QueueBackground(snapshot, tempPath, scanParams.OcrParams); } } } }
public static void PostProcessStep2(ScannedImage image, ScanProfile profile, int pageNumber) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { AddTransformAndUpdateThumbnail(image, new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { AddTransformAndUpdateThumbnail(image, new TrueContrastTransform { Contrast = profile.Contrast }); } } if (profile.FlipDuplexedPages && pageNumber % 2 == 0) { AddTransformAndUpdateThumbnail(image, new RotationTransform(RotateFlipType.Rotate180FlipNone)); } }
private Snapshot(SerializationInfo info, StreamingContext context) { Source = new ScannedImage((RecoveryIndexImage)info.GetValue("RecoveryIndexImage", typeof(RecoveryIndexImage))); TransformList = (List <Transform>)info.GetValue("TransformList", typeof(List <Transform>)); TransformState = (int)info.GetValue("TransformState", typeof(int)); }
private ScannedImage TransferImage(WiaBackgroundEventLoop eventLoop, int pageNumber, out bool cancel) { try { var transfer = ScanParams.NoUI ? backgroundWiaTransfer : foregroundWiaTransfer; ChaosMonkey.MaybeError(0.5, new COMException("Fail", -2147467259)); using (var stream = transfer.Transfer(pageNumber, eventLoop, WiaApi.Formats.BMP)) { if (stream == null) { cancel = true; return null; } cancel = false; using (Image output = Image.FromStream(stream)) { using (var result = ScannedImageHelper.PostProcessStep1(output, ScanProfile)) { if (blankDetector.ExcludePage(result, ScanProfile)) { return null; } ScanBitDepth bitDepth = ScanProfile.UseNativeUI ? ScanBitDepth.C24Bit : ScanProfile.BitDepth; var image = new ScannedImage(result, bitDepth, ScanProfile.MaxQuality, ScanProfile.Quality); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(result)); ScannedImageHelper.PostProcessStep2(image, result, ScanProfile, ScanParams, pageNumber); return image; } } } } catch (NoPagesException) { if (ScanProfile.PaperSource != ScanSource.Glass && pageNumber == 1) { // No pages were in the feeder, so show the user an error throw new NoPagesException(); } // At least one page was scanned but now the feeder is empty, so exit normally cancel = true; return null; } catch (ScanDriverException) { throw; } catch (Exception e) { throw new ScanDriverUnknownException(e); } }
public void ReceiveScannedImage(ScannedImage scannedImage) { Invoke(() => { imageList.Images.Add(scannedImage); AppendThumbnail(scannedImage); changeTracker.HasUnsavedChanges = true; Application.DoEvents(); }); }
public void ReceiveScannedImage(ScannedImage scannedImage) { imageList.Images.Add(scannedImage); pagesScanned++; totalPagesScanned++; OutputVerbose(ConsoleResources.ScannedPage, totalPagesScanned); }
public Bitmap RenderThumbnail(ScannedImage scannedImage, int size) { return(RenderThumbnail(scannedImage.GetImage(), size)); }
public Bitmap RenderThumbnail(ScannedImage scannedImage) { return RenderThumbnail(scannedImage.GetImage(), userConfigManager.Config.ThumbnailSize); }
public Bitmap RenderThumbnail(ScannedImage scannedImage) { return(RenderThumbnail(scannedImageRenderer.Render(scannedImage), userConfigManager.Config.ThumbnailSize)); }
public List<ScannedImage> Scan(IWin32Window dialogParent, bool activate, ScanDevice scanDevice, ScanProfile scanProfile, ScanParams scanParams) { if (scanProfile.TwainImpl == TwainImpl.Legacy) { return Legacy.TwainApi.Scan(scanProfile, scanDevice, dialogParent, formFactory); } var session = new TwainSession(TwainAppId); var twainForm = formFactory.Create<FTwainGui>(); var images = new List<ScannedImage>(); Exception error = null; bool cancel = false; DataSource ds = null; session.TransferReady += (sender, eventArgs) => { Debug.WriteLine("NAPS2.TW - TransferReady"); if (cancel) { eventArgs.CancelAll = true; } }; session.DataTransferred += (sender, eventArgs) => { Debug.WriteLine("NAPS2.TW - DataTransferred"); using (var output = Image.FromStream(eventArgs.GetNativeImageStream())) { using (var result = ScannedImageHelper.PostProcessStep1(output, scanProfile)) { if (blankDetector.ExcludePage(result, scanProfile)) { return; } var bitDepth = output.PixelFormat == PixelFormat.Format1bppIndexed ? ScanBitDepth.BlackWhite : ScanBitDepth.C24Bit; var image = new ScannedImage(result, bitDepth, scanProfile.MaxQuality, scanProfile.Quality); ScannedImageHelper.PostProcessStep2(image, scanProfile); if (scanParams.DetectPatchCodes) { foreach (var patchCodeInfo in eventArgs.GetExtImageInfo(ExtendedImageInfo.PatchCode)) { if (patchCodeInfo.ReturnCode == ReturnCode.Success) { image.PatchCode = GetPatchCode(patchCodeInfo); } } } images.Add(image); } } }; session.TransferError += (sender, eventArgs) => { Debug.WriteLine("NAPS2.TW - TransferError"); if (eventArgs.Exception != null) { error = eventArgs.Exception; } else if (eventArgs.SourceStatus != null) { Log.Error("TWAIN Transfer Error. Return code = {0}; condition code = {1}; data = {2}.", eventArgs.ReturnCode, eventArgs.SourceStatus.ConditionCode, eventArgs.SourceStatus.Data); } else { Log.Error("TWAIN Transfer Error. Return code = {0}.", eventArgs.ReturnCode); } cancel = true; twainForm.Close(); }; session.SourceDisabled += (sender, eventArgs) => { Debug.WriteLine("NAPS2.TW - SourceDisabled"); twainForm.Close(); }; twainForm.Shown += (sender, eventArgs) => { if (activate) { // TODO: Set this flag based on whether NAPS2 already has focus // http://stackoverflow.com/questions/7162834/determine-if-current-application-is-activated-has-focus // Or maybe http://stackoverflow.com/questions/156046/show-a-form-without-stealing-focus twainForm.Activate(); } Debug.WriteLine("NAPS2.TW - TwainForm.Shown"); try { ReturnCode rc = session.Open(new WindowsFormsMessageLoopHook(dialogParent.Handle)); if (rc != ReturnCode.Success) { Debug.WriteLine("NAPS2.TW - Could not open session - {0}", rc); twainForm.Close(); return; } ds = session.FirstOrDefault(x => x.Name == scanDevice.ID); if (ds == null) { Debug.WriteLine("NAPS2.TW - Could not find DS - DS count = {0}", session.Count()); throw new DeviceNotFoundException(); } rc = ds.Open(); if (rc != ReturnCode.Success) { Debug.WriteLine("NAPS2.TW - Could not open DS - {0}", rc); twainForm.Close(); return; } ConfigureDS(ds, scanProfile, scanParams); var ui = scanProfile.UseNativeUI ? SourceEnableMode.ShowUI : SourceEnableMode.NoUI; Debug.WriteLine("NAPS2.TW - Enabling DS"); rc = ds.Enable(ui, true, twainForm.Handle); Debug.WriteLine("NAPS2.TW - Enable finished"); if (rc != ReturnCode.Success) { Debug.WriteLine("NAPS2.TW - Enable failed - {0}, rc"); twainForm.Close(); } } catch (Exception ex) { Debug.WriteLine("NAPS2.TW - Error"); error = ex; twainForm.Close(); } }; Debug.WriteLine("NAPS2.TW - Showing TwainForm"); twainForm.ShowDialog(dialogParent); Debug.WriteLine("NAPS2.TW - TwainForm closed"); if (ds != null && session.IsSourceOpen) { Debug.WriteLine("NAPS2.TW - Closing DS"); ds.Close(); } if (session.IsDsmOpen) { Debug.WriteLine("NAPS2.TW - Closing session"); session.Close(); } if (error != null) { Debug.WriteLine("NAPS2.TW - Throwing error - {0}", error); if (error is ScanDriverException) { throw error; } throw new ScanDriverUnknownException(error); } return images; }
public void ReplaceThumbnail(int index, ScannedImage img) { ilThumbnailList.Images[index] = thumbnails[img]; Invalidate(Items[index].Bounds); }
private ScannedImage TransferImage(WiaBackgroundEventLoop eventLoop, int pageNumber, out bool cancel) { try { // TODO: Use the NoUI flag uniformly var transfer = ScanParams.NoUI ? new ConsoleWiaTransfer() : wiaTransfer; using (var stream = transfer.Transfer(pageNumber, eventLoop, WiaApi.Formats.BMP)) { if (stream == null) { cancel = true; return null; } cancel = false; using (Image output = Image.FromStream(stream)) { using (var result = ScannedImageHelper.PostProcessStep1(output, ScanProfile)) { if (blankDetector.ExcludePage(result, ScanProfile)) { return null; } ScanBitDepth bitDepth = ScanProfile.UseNativeUI ? ScanBitDepth.C24Bit : ScanProfile.BitDepth; var image = new ScannedImage(result, bitDepth, ScanProfile.MaxQuality, ScanProfile.Quality); ScannedImageHelper.PostProcessStep2(image, ScanProfile); return image; } } } } catch (COMException e) { if ((uint)e.ErrorCode == WiaApi.Errors.OUT_OF_PAPER) { if (ScanProfile.PaperSource != ScanSource.Glass && pageNumber == 1) { throw new NoPagesException(); } cancel = true; return null; } else if ((uint)e.ErrorCode == WiaApi.Errors.OFFLINE) { throw new DeviceOfflineException(); } else { throw new ScanDriverUnknownException(e); } } }
private CropTransform ScaleCropTransform(ScannedImage img, Bitmap referenceBitmap) { using (var bitmap = img.GetImage()) { double xScale = bitmap.Width / (double)referenceBitmap.Width, yScale = bitmap.Height / (double)referenceBitmap.Height; return new CropTransform { Left = (int)Math.Round(CropTransform.Left * xScale), Right = (int)Math.Round(CropTransform.Right * xScale), Top = (int)Math.Round(CropTransform.Top * yScale), Bottom = (int)Math.Round(CropTransform.Bottom * yScale) }; } }
public static void PostProcessStep2(ScannedImage image, ScanProfile profile) { if (!profile.UseNativeUI && profile.BrightnessContrastAfterScan) { if (profile.Brightness != 0) { image.AddTransform(new BrightnessTransform { Brightness = profile.Brightness }); } if (profile.Contrast != 0) { image.AddTransform(new TrueContrastTransform { Contrast = profile.Contrast }); } } }
public void AppendImage(ScannedImage img) { ilThumbnailList.Images.Add(thumbnails[img]); Items.Add("", ilThumbnailList.Images.Count - 1); }
private ScannedImage ExportAsPngImage(PdfPage page, PdfDictionary imageObject) { int width = imageObject.Elements.GetInteger(PdfImage.Keys.Width); int height = imageObject.Elements.GetInteger(PdfImage.Keys.Height); int bitsPerComponent = imageObject.Elements.GetInteger(PdfImage.Keys.BitsPerComponent); var buffer = imageObject.Stream.UnfilteredValue; Bitmap bitmap; ScanBitDepth bitDepth; switch (bitsPerComponent) { case 8: bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); bitDepth = ScanBitDepth.C24Bit; RgbToBitmapUnmanaged(height, width, bitmap, buffer); break; case 1: bitmap = new Bitmap(width, height, PixelFormat.Format1bppIndexed); bitDepth = ScanBitDepth.BlackWhite; BlackAndWhiteToBitmapUnmanaged(height, width, bitmap, buffer); break; default: throw new NotImplementedException("Unsupported image encoding (expected 24 bpp or 1bpp)"); } using (bitmap) { bitmap.SetResolution(bitmap.Width / (float)page.Width.Inch, bitmap.Height / (float)page.Height.Inch); var image = new ScannedImage(bitmap, bitDepth, true, -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); return image; } }
private ScannedImage MakeImage() { var bitmap = new Bitmap(600, 800); using (Graphics g = Graphics.FromImage(bitmap)) { g.FillRectangle(Brushes.LightGray, 0, 0, bitmap.Width, bitmap.Height); g.DrawString((_number++).ToString("G"), new Font("Times New Roman", 80), Brushes.Black, 0, 350); } var image = new ScannedImage(bitmap, ScanBitDepth.C24Bit, ScanProfile.MaxQuality, ScanProfile.Quality); return image; }
public Bitmap RenderThumbnail(ScannedImage scannedImage, int size) { return(RenderThumbnail(scannedImageRenderer.Render(scannedImage), size)); }
public Task <Bitmap> RenderThumbnail(ScannedImage scannedImage) { return(RenderThumbnail(scannedImage, userConfigManager.Config.ThumbnailSize)); }
public Bitmap RenderThumbnail(ScannedImage scannedImage, int size) { return RenderThumbnail(scannedImage.GetImage(), size); }
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); } } } }
private ScannedImage ExportJpegImage(PdfPage page, byte[] imageBytes) { // Fortunately JPEG has native support in PDF and exporting an image is just writing the stream to a file. using (var memoryStream = new MemoryStream(imageBytes)) { using (var bitmap = new Bitmap(memoryStream)) { bitmap.SetResolution(bitmap.Width / (float)page.Width.Inch, bitmap.Height / (float)page.Height.Inch); var image = new ScannedImage(bitmap, ScanBitDepth.C24Bit, false, -1); image.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap)); return image; } } }
private bool DoRecover(Action<ScannedImage> imageCallback) { Status.MaxProgress = recoveryIndexManager.Index.Images.Count; InvokeStatusChanged(); foreach (RecoveryIndexImage indexImage in recoveryIndexManager.Index.Images) { if (cancel) { return false; } string imagePath = Path.Combine(folderToRecoverFrom.FullName, indexImage.FileName); ScannedImage scannedImage; using (var bitmap = new Bitmap(imagePath)) { scannedImage = new ScannedImage(bitmap, indexImage.BitDepth, indexImage.HighQuality, -1); } foreach (var transform in indexImage.TransformList) { scannedImage.AddTransform(transform); } scannedImage.SetThumbnail(thumbnailRenderer.RenderThumbnail(scannedImage)); imageCallback(scannedImage); Status.CurrentProgress++; InvokeStatusChanged(); } return true; }
public virtual void Put(ScannedImage image) => collection.Add(image);
private void AppendThumbnail(ScannedImage scannedImage) { thumbnailList1.AppendImage(scannedImage); UpdateToolbar(); }