Beispiel #1
0
        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="factory">
        /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
        /// the image to process.
        /// </param>
        /// <returns>
        /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public Image ProcessImage(ImageFactory factory)
        {
            Bitmap newImage = null;
            Image  image    = factory.Image;

            try
            {
                RoundedCornerLayer roundedCornerLayer = this.DynamicParameter;
                int   radius          = roundedCornerLayer.Radius;
                Color backgroundColor = roundedCornerLayer.BackgroundColor;
                bool  topLeft         = roundedCornerLayer.TopLeft;
                bool  topRight        = roundedCornerLayer.TopRight;
                bool  bottomLeft      = roundedCornerLayer.BottomLeft;
                bool  bottomRight     = roundedCornerLayer.BottomRight;

                // Create a rotated image.
                newImage = this.RoundCornerImage(image, radius, backgroundColor, topLeft, topRight, bottomLeft, bottomRight);

                image.Dispose();
                image = newImage;
            }
            catch
            {
                if (newImage != null)
                {
                    newImage.Dispose();
                }
            }

            return(image);
        }
Beispiel #2
0
        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="factory">
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
        /// the image to process.
        /// </param>
        /// <returns>
        /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public Image ProcessImage(ImageFactory factory)
        {
            Bitmap newImage = null;
            Image  image    = factory.Image;

            try
            {
                RoundedCornerLayer roundedCornerLayer = this.DynamicParameter;
                int  radius      = roundedCornerLayer.Radius;
                bool topLeft     = roundedCornerLayer.TopLeft;
                bool topRight    = roundedCornerLayer.TopRight;
                bool bottomLeft  = roundedCornerLayer.BottomLeft;
                bool bottomRight = roundedCornerLayer.BottomRight;

                // Create a rounded image.
                newImage = this.RoundCornerImage(image, radius, topLeft, topRight, bottomLeft, bottomRight);

                image.Dispose();
                image = newImage;
            }
            catch (Exception ex)
            {
                if (newImage != null)
                {
                    newImage.Dispose();
                }

                throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
            }

            return(image);
        }
        /// <summary>
        /// The position in the original string where the first character of the captured substring was found.
        /// </summary>
        /// <param name="queryString">The query string to search.</param>
        /// <returns>
        /// The zero-based starting position in the original string where the captured substring was found.
        /// </returns>
        public int MatchRegexIndex(string queryString)
        {
            int index = 0;

            // Set the sort order to max to allow filtering.
            this.SortOrder = int.MaxValue;

            foreach (Match match in this.RegexPattern.Matches(queryString))
            {
                if (match.Success)
                {
                    if (index == 0)
                    {
                        // Set the index on the first instance only.
                        this.SortOrder = match.Index;

                        RoundedCornerLayer roundedCornerLayer = new RoundedCornerLayer(
                            this.ParseRadius(queryString),
                            this.ParseCorner(TopLeftRegex, queryString),
                            this.ParseCorner(TopRightRegex, queryString),
                            this.ParseCorner(BottomLeftRegex, queryString),
                            this.ParseCorner(BottomRightRegex, queryString));

                        this.Processor.DynamicParameter = roundedCornerLayer;
                    }

                    index += 1;
                }
            }

            return(this.SortOrder);
        }
        /// <summary>
        /// Returns a value that indicates whether the specified object is an
        /// <see cref="RoundedCornerLayer"/> object that is equivalent to
        /// this <see cref="RoundedCornerLayer"/> object.
        /// </summary>
        /// <param name="obj">
        /// The object to test.
        /// </param>
        /// <returns>
        /// True if the given object is an <see cref="RoundedCornerLayer"/> object that is equivalent to
        /// this <see cref="RoundedCornerLayer"/> object; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            RoundedCornerLayer rounded = obj as RoundedCornerLayer;

            if (rounded == null)
            {
                return(false);
            }

            return(this.Radius == rounded.Radius &&
                   this.TopLeft == rounded.TopLeft && this.TopRight == rounded.TopRight &&
                   this.BottomLeft == rounded.BottomLeft && this.BottomRight == rounded.BottomRight);
        }
        public void TestRoundedCornersRegex()
        {
            const string       Querystring = "roundedcorners=30";
            RoundedCornerLayer expected    = new RoundedCornerLayer(30, true, true, true, true);

            RoundedCorners roundedCorners = new RoundedCorners();

            roundedCorners.MatchRegexIndex(Querystring);

            RoundedCornerLayer actual = roundedCorners.DynamicParameter;

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Adds rounded corners to the current image.
        /// </summary>
        /// <param name="roundedCornerLayer">
        /// The <see cref="T:ImageProcessor.Imaging.RoundedCornerLayer"/> containing the properties to round corners on the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public ImageFactory RoundedCorners(RoundedCornerLayer roundedCornerLayer)
        {
            if (this.ShouldProcess)
            {
                if (roundedCornerLayer.Radius < 0)
                {
                    roundedCornerLayer.Radius = 0;
                }

                RoundedCorners roundedCorners = new RoundedCorners {
                    DynamicParameter = roundedCornerLayer
                };
                this.CurrentImageFormat.ApplyProcessor(roundedCorners.ProcessImage, this);
            }

            return(this);
        }
Beispiel #7
0
        /// <summary>
        /// Rotates the current image by the given angle.
        /// </summary>
        /// <param name="rotateLayer">
        /// The <see cref="T:ImageProcessor.Imaging.RotateLayer"/> containing the properties to rotate the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        //public ImageFactory Rotate(RotateLayer rotateLayer)
        //{
        //    if (this.ShouldProcess)
        //    {
        //        // Sanitize the input.
        //        if (rotateLayer.Angle > 360 || rotateLayer.Angle < 0)
        //        {
        //            rotateLayer.Angle = 0;
        //        }

        //        Rotate rotate = new Rotate { DynamicParameter = rotateLayer };

        //        this.Image = rotate.ProcessImage(this);
        //    }

        //    return this;
        //}

        /// <summary>
        /// Adds rounded corners to the current image.
        /// </summary>
        /// <param name="roundedCornerLayer">
        /// The <see cref="T:ImageProcessor.Imaging.RoundedCornerLayer"/> containing the properties to round corners on the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public ImageFactory RoundedCorners(RoundedCornerLayer roundedCornerLayer)
        {
            if (this.ShouldProcess)
            {
                if (roundedCornerLayer.Radius < 0)
                {
                    roundedCornerLayer.Radius = 0;
                }

                RoundedCorners roundedCorners = new RoundedCorners {
                    DynamicParameter = roundedCornerLayer
                };

                this.Image = roundedCorners.ProcessImage(this);
            }

            return(this);
        }
        public void TestRoundedCornersRegex()
        {
            Dictionary <string, RoundedCornerLayer> data = new Dictionary <string, RoundedCornerLayer>
            {
                {
                    "roundedcorners=30", new RoundedCornerLayer(30)
                },
                {
                    "roundedcorners=26&tl=true&tr=false&bl=true&br=false", new RoundedCornerLayer(26, true, false, true, false)
                }
            };

            Processors.RoundedCorners roundedCorners = new Processors.RoundedCorners();
            foreach (KeyValuePair <string, RoundedCornerLayer> item in data)
            {
                roundedCorners.MatchRegexIndex(item.Key);
                RoundedCornerLayer result = roundedCorners.Processor.DynamicParameter;
                Assert.AreEqual(item.Value, result);
            }
        }
Beispiel #9
0
        /// <summary>
        /// The position in the original string where the first character of the captured substring was found.
        /// </summary>
        /// <param name="queryString">
        /// The query string to search.
        /// </param>
        /// <returns>
        /// The zero-based starting position in the original string where the captured substring was found.
        /// </returns>
        public int MatchRegexIndex(string queryString)
        {
            int index = 0;

            // Set the sort order to max to allow filtering.
            this.SortOrder = int.MaxValue;

            foreach (Match match in this.RegexPattern.Matches(queryString))
            {
                if (match.Success)
                {
                    if (index == 0)
                    {
                        // Set the index on the first instance only.
                        this.SortOrder = match.Index;

                        RoundedCornerLayer roundedCornerLayer;

                        string toParse = match.Value;

                        if (toParse.Contains("bgcolor"))
                        {
                            roundedCornerLayer = new RoundedCornerLayer(this.ParseRadius(toParse), this.ParseColor(toParse), this.ParseCorner(TopLeftRegex, toParse), this.ParseCorner(TopRightRegex, toParse), this.ParseCorner(BottomLeftRegex, toParse), this.ParseCorner(BottomRightRegex, toParse));
                        }
                        else
                        {
                            int radius;
                            int.TryParse(match.Value.Split('=')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out radius);

                            roundedCornerLayer = new RoundedCornerLayer(radius, this.ParseCorner(TopLeftRegex, toParse), this.ParseCorner(TopRightRegex, toParse), this.ParseCorner(BottomLeftRegex, toParse), this.ParseCorner(BottomRightRegex, toParse));
                        }

                        this.DynamicParameter = roundedCornerLayer;
                    }

                    index += 1;
                }
            }

            return(this.SortOrder);
        }
        /// <summary>
        /// The position in the original string where the first character of the captured substring was found.
        /// </summary>
        /// <param name="queryString">The query string to search.</param>
        /// <returns>
        /// The zero-based starting position in the original string where the captured substring was found.
        /// </returns>
        public int MatchRegexIndex(string queryString)
        {
            this.SortOrder = int.MaxValue;
            Match match = this.RegexPattern.Match(queryString);

            if (match.Success)
            {
                this.SortOrder = match.Index;
                NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString);

                RoundedCornerLayer roundedCornerLayer = new RoundedCornerLayer(
                    QueryParamParser.Instance.ParseValue <int>(queryCollection["roundedcorners"]),
                    this.ParseCorner(queryCollection, "tl"),
                    this.ParseCorner(queryCollection, "tr"),
                    this.ParseCorner(queryCollection, "bl"),
                    this.ParseCorner(queryCollection, "br"));

                this.Processor.DynamicParameter = roundedCornerLayer;
            }

            return(this.SortOrder);
        }
Beispiel #11
0
        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="factory">
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
        /// the image to process.
        /// </param>
        /// <returns>
        /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public Image ProcessImage(ImageFactory factory)
        {
            var image = factory.Image;

            try
            {
                RoundedCornerLayer roundedCornerLayer = DynamicParameter;
                var radius      = roundedCornerLayer.Radius;
                var topLeft     = roundedCornerLayer.TopLeft;
                var topRight    = roundedCornerLayer.TopRight;
                var bottomLeft  = roundedCornerLayer.BottomLeft;
                var bottomRight = roundedCornerLayer.BottomRight;

                // Create a rounded image.
                image = RoundCornerImage(image, radius, topLeft, topRight, bottomLeft, bottomRight);

                return(image);
            }
            catch (Exception ex)
            {
                throw new ImageProcessingException("Error processing image with " + GetType().Name, ex);
            }
        }