Пример #1
0
        /// <summary>
        /// Rotates image
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="angle">Angle of rotation</param>
        /// <param name="fillColor">Fill color</param>
        /// <returns></returns>
        public static Bitmap Rotate(Bitmap bitmap, float angle, Color fillColor)
        {
            Bitmap resultImage = bitmap;

            if (angle != 0)
            {
                GdPictureImaging image = new GdPictureImaging();

                int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

                try
                {
                    if (imageId > 0)
                    {
                        image.RotateAngleBackColor(imageId, angle, fillColor);
                        resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                    }
                }
                finally
                {
                    image.ReleaseGdPictureImage(imageId);
                }
            }

            return(resultImage);
        }
Пример #2
0
        /// <summary>
        /// Get skew angle
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="exludeBorders">Excluding borders from reaserch</param>
        /// <param name="percentageOfExcludableBorders">Percent of excluded borders</param>
        /// <returns></returns>
        public static float GetSkewAngle(Bitmap bitmap, bool exludeBorders = false, int percentageOfExcludableBorders = 0)
        {
            GdPictureImaging image = new GdPictureImaging();
            float            angle = 0;

            try
            {
                int imageId = image.CreateGdPictureImageFromBitmap(bitmap);
                if (imageId > 0)
                {
                    if (exludeBorders)
                    {
                        int width  = image.GetWidth(imageId);
                        int height = image.GetHeight(imageId);
                        int left   = width / 100 * percentageOfExcludableBorders;
                        int top    = width / 100 * percentageOfExcludableBorders;
                        image.Crop(imageId, left, top, width - 2 * left, height - 2 * top);
                    }
                    angle = image.GetSkewAngle(imageId, MaxAngleOfDeskewResearch, AngleResearchStep, true);
                    image.ReleaseGdPictureImage(imageId);
                }
            }
            catch (Exception e)
            {
            }

            return(angle);
        }
Пример #3
0
        /// <summary>
        /// Removes blobs from image
        /// </summary>
        /// <param name="bitmap">Bitmap.</param>
        /// <param name="blobsDimensions">Blobs dimensions</param>
        /// <returns></returns>
        public static Bitmap RemoveBlobs(Bitmap bitmap, BlobsDimensions blobsDimensions)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            try
            {
                if (imageId > 0)
                {
                    if (image.GetBitDepth(imageId) != 1)
                    {
                        image.ConvertTo1BppAT(imageId);
                    }

                    image.RemoveBlob(imageId, blobsDimensions.MinBlobWidth, blobsDimensions.MinBlobHeight, blobsDimensions.MaxBlobWidth, blobsDimensions.MaxBlobHeight, BlobRemoveMode.FavorQuality);
                    resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                }
            }
            finally
            {
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #4
0
        /// <summary>
        /// Removes staple marks
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <returns></returns>
        public static Bitmap RemoveStapleMarks(Bitmap bitmap)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            try
            {
                if (imageId > 0)
                {
                    if (image.GetBitDepth(imageId) != 1)
                    {
                        image.ConvertTo1BppAT(imageId);
                    }

                    image.RemoveStapleMark(imageId);
                    resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                }
            }
            catch
            {
            }
            finally
            {
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #5
0
        /// <summary>
        /// Set gamma for specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="gamma">Gamma (values from -100 to 100)</param>
        /// <returns></returns>
        public static Bitmap SetGammaCorrection(Bitmap bitmap, int gamma)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                image.SetGammaCorrection(imageId, gamma);
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #6
0
        /// <summary>
        /// Set contrast for specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="contrast">Contrast (values from -100 to 100)</param>
        /// <returns></returns>
        public static Bitmap SetContrast(Bitmap bitmap, int contrast)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                image.SetContrast(imageId, contrast);
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #7
0
        /// <summary>
        /// Binarizes the specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="threshold">Threshold</param>
        /// <returns></returns>
        public static Bitmap Binarize(Bitmap bitmap, byte threshold)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                image.ConvertTo1Bpp(imageId, threshold);
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #8
0
        /// <summary>
        /// Crops the specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="rectangle">Rectangle</param>
        /// <returns></returns>
        public static Bitmap Crop(Bitmap bitmap, Rectangle rectangle)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                image.Crop(imageId, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #9
0
        /// <summary>
        /// Removes lines
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="orientation">Lines orientation</param>
        /// <returns></returns>
        public static Bitmap RemoveLines(Bitmap bitmap, Enums.LineRemoveOrientation orientation)
        {
            Bitmap resultImage = bitmap;

            LineRemoveOrientation lineRemoveOrientation;

            switch (orientation)
            {
            case Enums.LineRemoveOrientation.Horizontal:
                lineRemoveOrientation = LineRemoveOrientation.Horizontal;
                break;

            case Enums.LineRemoveOrientation.Vertical:
                lineRemoveOrientation = LineRemoveOrientation.Vertical;
                break;

            default:
                return(resultImage);
            }

            if (orientation != Enums.LineRemoveOrientation.None)
            {
                GdPictureImaging image = new GdPictureImaging();

                int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

                try
                {
                    if (imageId > 0)
                    {
                        if (image.GetBitDepth(imageId) != 1)
                        {
                            image.ConvertTo1BppAT(imageId);
                        }

                        image.RemoveLines(imageId, lineRemoveOrientation);
                        resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                    }
                }
                finally
                {
                    image.ReleaseGdPictureImage(imageId);
                }
            }

            return(resultImage);
        }
Пример #10
0
        /// <summary>
        /// Removes the holes from holemaker
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="punchHolesPosition">Holes position</param>
        /// <returns></returns>
        public static Bitmap RemovePunchHoles(Bitmap bitmap, PunchHolesPositions punchHolesPosition)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            try
            {
                if (imageId > 0)
                {
                    if (image.GetBitDepth(imageId) != 1)
                    {
                        image.ConvertTo1BppAT(imageId);
                    }

                    if (punchHolesPosition.LeftSide)
                    {
                        image.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft);
                    }
                    if (punchHolesPosition.TopSide)
                    {
                        image.RemoveHolePunch(imageId, HolePunchMargins.MarginTop);
                    }
                    if (punchHolesPosition.RightSide)
                    {
                        image.RemoveHolePunch(imageId, HolePunchMargins.MarginRight);
                    }
                    if (punchHolesPosition.BottomSide)
                    {
                        image.RemoveHolePunch(imageId, HolePunchMargins.MarginBottom);
                    }

                    resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #11
0
        /// <summary>
        /// Binarizes the specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <returns></returns>
        public static Bitmap Binarize(Bitmap bitmap)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                image.FxBlackNWhite(imageId, BitonalReduction.Stucki);
                image.ConvertTo1BppFast(imageId);
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #12
0
        /// <summary>
        /// Set sharpness for specified bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="sharpness">Sharpness</param>
        /// <returns></returns>
        public static Bitmap SetSharpness(Bitmap bitmap, int sharpness)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            if (imageId > 0)
            {
                for (int i = 0; i < sharpness; i++)
                {
                    image.FxSharpen(imageId);
                }
                resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #13
0
        public static string CleHole(Bitmap bmp)
        {
            string         file            = "";
            LicenseManager oLicenceManager = new LicenseManager();

            oLicenceManager.RegisterKEY(T_ConFigure.Imgid);
            using (GdPictureImaging oGdPictureImaging = new GdPictureImaging()) {
                int imageId = oGdPictureImaging.CreateGdPictureImageFromBitmap(bmp);
                if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
                {
                    return(file);
                }
                else
                {
                    GdPictureStatus status = oGdPictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginAll);
                    if (status != GdPictureStatus.OK)
                    {
                        return(file);
                    }
                    else
                    {
                        string path = @"c:\temp\cle";
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        file = Path.Combine(path, DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg");
                        if (File.Exists(file))
                        {
                            File.Delete(file);
                        }
                        status = oGdPictureImaging.SaveAsTIFF(imageId, file, TiffCompression.TiffCompressionJPEG);
                        if (status != GdPictureStatus.OK)
                        {
                            return("");
                        }
                    }
                    oGdPictureImaging.ReleaseGdPictureImage(imageId);
                }
            }
            return(file);
        }
Пример #14
0
        /// <summary>
        /// Removes noise
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <returns></returns>
        public static Bitmap RemoveNoise(Bitmap bitmap)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            try
            {
                if (imageId > 0)
                {
                    image.FxDespeckleMore(imageId);
                    resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                }
            }
            finally
            {
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }
Пример #15
0
        /// <summary>
        /// Auto crop borders
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <returns></returns>
        public static Bitmap AutoCropBorders(Bitmap bitmap)
        {
            Bitmap           resultImage = bitmap;
            GdPictureImaging image       = new GdPictureImaging();

            int imageId = image.CreateGdPictureImageFromBitmap(bitmap);

            try
            {
                if (imageId > 0)
                {
                    image.CropBorders(imageId, ImagingContext.ContextDocument);
                    resultImage = image.GetBitmapFromGdPictureImage(imageId).CloneSmart(image.GetPixelFormat(imageId));
                }
            }
            finally
            {
                image.ReleaseGdPictureImage(imageId);
            }

            return(resultImage);
        }