/// <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 { RotateLayer rotateLayer = this.DynamicParameter; int angle = rotateLayer.Angle; Color backgroundColor = rotateLayer.BackgroundColor; // Center of the image float rotateAtX = Math.Abs(image.Width / 2); float rotateAtY = Math.Abs(image.Height / 2); // Create a rotated image. newImage = this.RotateImage(image, rotateAtX, rotateAtY, angle, backgroundColor); image.Dispose(); image = newImage; } catch { if (newImage != null) { newImage.Dispose(); } } return(image); }
public void TestRotateRegex() { const string Querystring = "rotate=270"; RotateLayer expected = new RotateLayer(270, Color.Transparent); Rotate rotate = new Rotate(); rotate.MatchRegexIndex(Querystring); RotateLayer actual = rotate.DynamicParameter; Assert.AreEqual(expected, actual); }
/// <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.ApplyProcessor(rotate.ProcessImage); } return(this); }
/// <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; RotateLayer rotateLayer; string toParse = match.Value; if (toParse.Contains("bgcolor")) { rotateLayer = new RotateLayer(this.ParseAngle(toParse), this.ParseColor(toParse)); } else { int degrees; int.TryParse(match.Value.Split('=')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out degrees); rotateLayer = new RotateLayer(degrees); } this.DynamicParameter = rotateLayer; } index += 1; } } return(this.SortOrder); }