Exemple #1
0
        private PdfShot GetPdfDocument(Image fullPageImage, ShotOptions options, String title)
        {
            var magicImage = new MagickImage(fullPageImage.ToMemoryStream());

            magicImage.Strip();

            if (options.IsGrayscale)
            {
                magicImage.Grayscale(PixelIntensityMethod.Lightness);
                magicImage.Contrast();
            }

            var partsCount = Math.Ceiling((Decimal)magicImage.Height / options.StepHeight);

            partsCount = Math.Ceiling((magicImage.Height + options.OverlaySize * partsCount) / options.StepHeight);

            var pageImageParts = new List <Byte[]>();

            for (var i = 0; i < partsCount; i++)
            {
                var y      = i * options.StepHeight - i * options.OverlaySize;
                var images = magicImage.CropToTiles(new MagickGeometry(0,
                                                                       y,
                                                                       options.Width,
                                                                       options.StepHeight))
                             .ToList();
                pageImageParts.Add(images.First().ToByteArray());
            }

            var pdfBytes = _pdfCreator.CreateDocument(options.Width, options.StepHeight, pageImageParts);

            return(new PdfShot(pdfBytes, GetFileName(title)));
        }
Exemple #2
0
 public void Compress()
 {
     using (MagickImage image = new MagickImage(_filePath))
     {
         image.Quality = 3;
         image.Contrast(true);
         image.Grayscale(PixelIntensityMethod.Lightness);
         image.AdaptiveThreshold(320, 240);
         image.Write(Destination);
     }
 }
Exemple #3
0
        private Bitmap processImgForScanning(Bitmap imgInput)
        {
            using (MemoryStream memstream = new MemoryStream())
            {
                imgInput.Save(memstream, ImageFormat.Tiff);
                MagickImage img = new MagickImage(memstream.ToArray());


                if (sharpen)
                {
                    img.Sharpen((int)sharpenIntX.Value, (int)sharpenIntY.Value, Channels.All);
                }

                if (autoGamma)
                {
                    img.AutoGamma();
                }

                if (enhance)
                {
                    img.Enhance();
                }

                if (contrast)
                {
                    img.Contrast();
                }

                if (autoLevel)
                {
                    img.AutoLevel();
                }

                if (autoOrient)
                {
                    img.AutoOrient();
                }

                if (despeckle)
                {
                    img.Despeckle();
                }


                if (medianFilter)
                {
                    img.MedianFilter((int)medianInt.Value);
                }

                if (unsharpmask)
                {
                    img.Unsharpmask(6.8, 4, 4, 0);
                }

                if (wtThreshold)
                {
                    img.LinearStretch((float)0.9, 0.1);
                    //img.WhiteThreshold((int)wtThresInt.Value);
                    //img.ReduceNoise();
                    //img.Grayscale(PixelIntensityMethod.Brightness);
                }

                if (invert)
                {
                    img.Negate();
                }

                return(img.ToBitmap());
            }
        }