// Methods /// <summary> /// Utility method that returns a query string representation based on the provided parameter values. /// </summary> /// <param name="source">The image source.</param> /// <param name="width">The image width.</param> /// <param name="height">The image height.</param> /// <param name="clientCacheDuration">The image client cache duration.</param> /// <param name="serverCacheDuration">The image server cache duration.</param> /// <param name="rotateFlip">The image rotate flip type.</param> /// <param name="drawGrayscale">The image draw grayscale type.</param> /// <param name="drawSepia">The image draw sepia type.</param> /// <param name="text">The image dynamic text.</param> /// <param name="gradientBackground">The button gradient background.</param> /// <param name="sizeType">The button size type.</param> /// <param name="textRenderTime">The time when the text is rendered.</param> internal static string ToQueryString( int width, int height, int clientCacheDuration, int serverCacheDuration, RotateFlipType rotateFlip, bool drawGrayscale, bool drawSepia, DynamicText text, DynamicImageFormat imageFormat, KeyValuePair<Type, IDictionary<string, string>>? imageCreator, Dictionary<Type, IDictionary<string, string>> imageTransformations, GradientBackground gradientBackground, TextContainerSizeType sizeType) { string dynamicImageQueryString = DynamicImageProvider.ToQueryString( null, width, height, clientCacheDuration, serverCacheDuration, rotateFlip, drawGrayscale, drawSepia, text, imageFormat, imageCreator, imageTransformations); List<string> parameters = new List<string>(); string parameterFormat = "{0}={1}"; if (null != gradientBackground) { // gradient border color if (Color.Gray != gradientBackground.BorderColor) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGCOLOR_KEY, gradientBackground.BorderColor.ToArgb())); } // gradient start color if (Color.Brown != gradientBackground.GradientStartColor) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGSTARTCOLOR_KEY, gradientBackground.GradientStartColor.ToArgb())); } // gradient end color if (Color.White != gradientBackground.GradientEndColor) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGENDCOLOR_KEY, gradientBackground.GradientEndColor.ToArgb())); } // gradient round corner radius if (0 <= gradientBackground.RoundCornerRadius) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGRCORNER_KEY, gradientBackground.RoundCornerRadius)); } // gradient border width if (0 <= gradientBackground.BorderWidth) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGBWIDTH_KEY, gradientBackground.BorderWidth)); } // gradient type if (GradientType.BackwardDiagonal != gradientBackground.Type) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGTYPE_KEY, gradientBackground.Type)); } // gradient inner border color if (Color.Gray != gradientBackground.InnerBorderColor) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGIBCOLOR_KEY, gradientBackground.InnerBorderColor.ToArgb())); } // gradient inner border width if (0 <= gradientBackground.InnerBorderWidth) { parameters.Add(string.Format(parameterFormat, GradientButtonImageTransformation.GRADIENTBKGIBWIDTH_KEY, gradientBackground.InnerBorderWidth)); } } // size type if (TextContainerSizeType.Specified != sizeType) { parameters.Add(string.Format(parameterFormat, TextDependentImageCreator.TEXTCONTSIZETYPE_KEY, sizeType)); } return (0 < parameters.Count) ? string.Concat(dynamicImageQueryString, "&", string.Join("&", parameters.ToArray())) : dynamicImageQueryString; }
// Methods internal static bool ParseGradientBackground(NameValueCollection parameters, out GradientBackground gradientBackground) { if (null != parameters) { gradientBackground = new GradientBackground(); if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGCOLOR_KEY])) { gradientBackground.BorderColor = Color.FromArgb(int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGCOLOR_KEY])); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGSTARTCOLOR_KEY])) { gradientBackground.GradientStartColor = Color.FromArgb(int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGSTARTCOLOR_KEY])); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGENDCOLOR_KEY])) { gradientBackground.GradientEndColor = Color.FromArgb(int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGENDCOLOR_KEY])); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGRCORNER_KEY])) { gradientBackground.RoundCornerRadius = int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGRCORNER_KEY]); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGBWIDTH_KEY])) { gradientBackground.BorderWidth = int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGBWIDTH_KEY]); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGTYPE_KEY])) { gradientBackground.Type = (GradientType)Enum.Parse(typeof(GradientType), parameters[GradientButtonImageTransformation.GRADIENTBKGTYPE_KEY]); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGIBCOLOR_KEY])) { gradientBackground.InnerBorderColor = Color.FromArgb(int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGIBCOLOR_KEY])); } if (!string.IsNullOrEmpty(parameters[GradientButtonImageTransformation.GRADIENTBKGIBWIDTH_KEY])) { gradientBackground.InnerBorderWidth = int.Parse(parameters[GradientButtonImageTransformation.GRADIENTBKGIBWIDTH_KEY]); } return true; } else { gradientBackground = null; return false; } }