RenderThumbnail() public method

public RenderThumbnail ( Bitmap b ) : Bitmap
b System.Drawing.Bitmap
return System.Drawing.Bitmap
Example #1
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);
     }
 }
Example #2
0
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };
            cancel = false;

            thread = threadFactory.StartThread(() =>
            {
                var memoryLimitingSem = new Semaphore(4, 4);
                Pipeline.For(images).StepParallel(img =>
                {
                    if (cancel)
                    {
                        return(null);
                    }
                    memoryLimitingSem.WaitOne();
                    Bitmap bitmap = scannedImageRenderer.Render(img);
                    try
                    {
                        if (cancel)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (cancel)
                        {
                            return(null);
                        }
                        bitmap = transform.Perform(bitmap);
                        img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap));

                        // The final pipeline step is pretty fast, so updating progress here is more accurate
                        lock (this)
                        {
                            Status.CurrentProgress += 1;
                        }
                        InvokeStatusChanged();

                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                        memoryLimitingSem.Release();
                    }
                }).Step((img, transform) =>
                {
                    img.AddTransform(transform);
                    return(img);
                }).Run();
                Status.Success = !cancel;
                InvokeFinished();
            });

            return(true);
        }
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };

            RunAsync(() =>
            {
                var memoryLimitingSem = new Semaphore(4, 4);
                Pipeline.For(images).StepParallel(img =>
                {
                    if (CancelToken.IsCancellationRequested)
                    {
                        return(null);
                    }
                    memoryLimitingSem.WaitOne();
                    var bitmap = scannedImageRenderer.Render(img).Result;
                    try
                    {
                        if (CancelToken.IsCancellationRequested)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (CancelToken.IsCancellationRequested)
                        {
                            return(null);
                        }
                        bitmap        = transform.Perform(bitmap);
                        var thumbnail = thumbnailRenderer.RenderThumbnail(bitmap);
                        lock (img)
                        {
                            img.AddTransform(transform);
                            img.SetThumbnail(thumbnail);
                        }

                        // The final pipeline step is pretty fast, so updating progress here is more accurate
                        lock (this)
                        {
                            Status.CurrentProgress += 1;
                        }
                        InvokeStatusChanged();

                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                        memoryLimitingSem.Release();
                    }
                }).Run();
                return(!CancelToken.IsCancellationRequested);
            });

            return(true);
        }
Example #4
0
 public IEnumerable <int> ResetTransforms(IEnumerable <int> selection)
 {
     foreach (ScannedImage img in Images.ElementsAt(selection))
     {
         img.ResetTransforms();
         img.SetThumbnail(ThumbnailRenderer.RenderThumbnail(img));
     }
     return(selection.ToList());
 }
Example #5
0
 public IEnumerable <int> RotateFlip(IEnumerable <int> selection, RotateFlipType rotateFlipType)
 {
     foreach (int i in selection)
     {
         Images[i].AddTransform(new RotationTransform(rotateFlipType));
         Images[i].SetThumbnail(ThumbnailRenderer.RenderThumbnail(Images[i]));
     }
     return(selection.ToList());
 }
Example #6
0
 public IEnumerable <int> ResetTransforms(IEnumerable <int> selection)
 {
     Parallel.ForEach(Images.ElementsAt(selection).ToList(), img =>
     {
         img.ResetTransforms();
         img.SetThumbnail(ThumbnailRenderer.RenderThumbnail(img));
     });
     return(selection.ToList());
 }
Example #7
0
 public IEnumerable <int> RotateFlip(IEnumerable <int> selection, RotateFlipType rotateFlipType)
 {
     Parallel.ForEach(selection.ToList(), i =>
     {
         Images[i].AddTransform(new RotationTransform(rotateFlipType));
         Images[i].SetThumbnail(ThumbnailRenderer.RenderThumbnail(Images[i]));
     });
     return(selection.ToList());
 }
Example #8
0
        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));
            }
        }
Example #9
0
 public Bitmap GetThumbnail(ThumbnailRenderer thumbnailRenderer)
 {
     if (thumbnail == null)
     {
         if (thumbnailRenderer == null)
         {
             return(null);
         }
         thumbnail = thumbnailRenderer.RenderThumbnail(this);
     }
     Debug.Assert(thumbnail != null);
     return((Bitmap)thumbnail.Clone());
 }
Example #10
0
        public bool Start(ICollection <ScannedImage> images)
        {
            ProgressTitle = MiscResources.AutoDeskewProgress;
            Status        = new OperationStatus
            {
                StatusText  = MiscResources.AutoDeskewing,
                MaxProgress = images.Count
            };
            cancel = false;

            thread = threadFactory.StartThread(() =>
            {
                Pipeline.For(images).StepParallel(img =>
                {
                    if (cancel)
                    {
                        return(null);
                    }
                    Bitmap bitmap = img.GetImage();
                    try
                    {
                        if (cancel)
                        {
                            return(null);
                        }
                        var transform = RotationTransform.Auto(bitmap);
                        if (cancel)
                        {
                            return(null);
                        }
                        bitmap = transform.Perform(bitmap);
                        img.SetThumbnail(thumbnailRenderer.RenderThumbnail(bitmap));
                        return(Tuple.Create(img, transform));
                    }
                    finally
                    {
                        bitmap.Dispose();
                    }
                }).Step((img, transform) =>
                {
                    img.AddTransform(transform);
                    Status.CurrentProgress++;
                    InvokeStatusChanged();
                    return(img);
                }).Run();
                Status.Success = !cancel;
                InvokeFinished();
            });

            return(true);
        }
Example #11
0
 public Bitmap GetThumbnail(ThumbnailRenderer thumbnailRenderer)
 {
     if (thumbnail == null)
     {
         if (thumbnailRenderer == null)
         {
             return null;
         }
         thumbnail = thumbnailRenderer.RenderThumbnail(this);
     }
     Debug.Assert(thumbnail != null);
     return (Bitmap)thumbnail.Clone();
 }