protected VerificationCodeImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) { if (textProvider == null) { throw new ArgumentNullException("textProvider"); } if (size.Width < MinimumSize.Width || size.Height < MinimumSize.Height) { throw new ArgumentOutOfRangeException("size", size, "Errors.SizePositiveIntRequired"); } this.textProvider = textProvider; if (maximumCharacters.HasValue) { this.textProvider.MaximumCharacters = maximumCharacters.Value; } if (minimumCharacters.HasValue) { this.textProvider.MinimumCharacters = minimumCharacters.Value; } this.size = size; this.fonts = new List <Font>(textProvider.Fonts); this.textColors = new List <Color>(textProvider.Colors); this.characterSet = characterSet; }
public PartitionedVerificationCodeImage(Image background, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) : base(background, textProvider, characterSet, maximumCharacters, minimumCharacters) { if (textProvider == null) { throw new ArgumentNullException("textProvider"); } minFontSize = textProvider.MinimumFontSize; maxFontSize = textProvider.MaximumFontSize; }
protected BackgroundVerificationCodeImage(Image background, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) // NOTE: MinimumSize size is only specified when background is null so that ArgumentNullException may be thrown by this constructor // after the base constructor is finished. : base((background == null) ? MinimumSize : background.Size, textProvider, characterSet, maximumCharacters, minimumCharacters) { if (background == null) { throw new ArgumentNullException("background"); } this.background = background; }
public LineNoiseVerificationCodeImage(Size size, VerificationCodeTextProvider textProvider, IEnumerable <Color> colors, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) : base(size, textProvider, characterSet, maximumCharacters, minimumCharacters) { if (colors == null) { this.colors = new List <Color>(1); } else { this.colors = new List <Color>(colors); } if (this.colors.Count == 0) { this.colors.Add(Color.Black); } }
/// <summary> /// 加载TextProvider /// </summary> /// <param name="configHasSection"></param> /// <param name="section"></param> private static void InitializeTextProviders(bool configHasSection, VerificationCodeSection section) { //加载TextProvider 如果webconfig中没有配置 则加载默认的BasicEnglishAutoInputProtectionTextProvider if (configHasSection) { if (!initializedTextProviders) { ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); initializedTextProviders = true; } if (section.DefaultTextProvider.Equals(section.ElementInformation.Properties["defaultTextProvider"].DefaultValue)) { if (textProviders.Count > 0) { textProvider = textProviders[0]; } else { textProvider = new BasicEnglishVerificationCodeTextProvider( new[] { Color.Black, Color.Red, Color.Brown }, new[] { new Font("Times New Roman", 1), new Font("Arial", 1), new Font("Microsoft Sans Serif", 1) }); } } else { textProvider = textProviders[section.DefaultTextProvider]; } if (textProvider == null) { throw new InvalidOperationException("Errors.Config_Missing_TextProvider"); } } else if (textProvider == null) { section.TextProviders.Add(CreateProviderSettings(section.DefaultTextProvider, typeof(BasicEnglishVerificationCodeTextProvider), new KeyValuePair <string, string>("colors", "Red,Green,Blue,Brown"), new KeyValuePair <string, string>("fonts", "Times New Roman, Arial, Microsoft Sans Serif"))); ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); textProvider = textProviders[section.DefaultTextProvider]; } }
/// <summary> /// Creates an instance of <see cref="PartitionedAutoInputProtectionImage"/> for the specified <paramref name="size"/> /// and <paramref name="textProvider"/>. /// </summary> /// <remarks> /// Derived types can override this method to return a type that either composites or derives from /// <see cref="PartitionedAutoInputProtectionImage"/>. /// </remarks> /// <seealso cref="GenerateRandomAutoInputProtectionImage(Size,AutoInputProtectionTextProvider)"/> /// <param name="size">The dimensions of the image.</param> /// <param name="textProvider">The <see cref="AutoInputProtectionTextProvider"/> implementation that generates the text to be rendered.</param> /// <returns>An instance of <see cref="PartitionedAutoInputProtectionImage"/> for the specified <paramref name="size"/> /// and <paramref name="textProvider"/>.</returns> protected virtual PartitionedVerificationCodeImage GenerateImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) { PartitionedVerificationCodeImage image = new PartitionedVerificationCodeImage(size, textProvider, characterSet, maximumCharacters, minimumCharacters); if (margin != -1) { image.Margin = margin; } if (minRotation != -1) { image.MinimumCharacterRotation = minRotation; } if (maxRotation != -1) { image.MaximumCharacterRotation = maxRotation; } return(image); }
/// <summary> /// When implemented by a derived type, creates an instance of a type that derives from <see cref="AutoInputProtectionImage"/> /// that generates an image of the specified <paramref name="size"/> using the specified <paramref name="textProvider"/>. /// </summary> /// <remarks> /// This overload is used by the <see cref="AutoInputProtectionControl"/> control. /// </remarks> /// <seealso cref="AutoInputProtection.GenerateAutoInputProtectionImage"/> /// <seealso cref="GenerateAutoInputProtectionImage"/> /// <param name="size">The dimensions of the image.</param> /// <param name="textProvider"><see cref="AutoInputProtectionTextProvider"/> implementation to be used by the <see cref="AutoInputProtectionImage"/> implementation that is created.</param> /// <returns>An <see cref="AutoInputProtectionImage"/> implementation that can generate an image of the specified <paramref name="size"/> using the specified /// <paramref name="textProvider"/>.</returns> public abstract VerificationCodeImage GenerateRandomAutoInputProtectionImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters);
/// <summary> /// When implemented by a derived type, creates an instance of a type that derives from <see cref="AutoInputProtectionImage"/> /// that generates an image of the specified <paramref name="size"/>, using the specified <paramref name="name"/> and /// <paramref name="textProvider"/>. /// </summary> /// <remarks> /// <para> /// Derived types are not required to use the <paramref name="name"/> argument. This overload is not used by the /// <see cref="AutoInputProtectionControl"/> control. /// </para> /// <para> /// A derived type can use the specified <paramref name="name"/> to load or generate a background <see cref="Image"/> /// that is passed to <see cref="GenerateImage(Image,AutoInputProtectionTextProvider)"/>, which creates an instance of /// <see cref="PartitionedAutoInputProtectionImage"/> that is then returned to the caller immediately or wrapped by a specialized class that /// is returned instead. Alternatively, a derived type may override <see cref="GenerateImage(Image,AutoInputProtectionTextProvider)"/> to /// create a custom implementation that is then returned by this method as is. /// </para> /// <para> /// See <see cref="ResourceAutoInputProtectionImageProvider"/> for information about one particular usage of the <paramref name="name"/> argument. /// </para> /// </remarks> /// <seealso cref="AutoInputProtection.GenerateAutoInputProtectionImage"/> /// <seealso cref="GenerateRandomAutoInputProtectionImage"/> /// <param name="name"><see cref="String"/> that identifies a particular named resource, style or image.</param> /// <param name="size">The dimensions of the image.</param> /// <param name="textProvider"><see cref="AutoInputProtectionTextProvider"/> implementation to be used by the <see cref="AutoInputProtectionImage"/> implementation that is created.</param> /// <returns>An <see cref="AutoInputProtectionImage"/> implementation that can generate an image of the specified <paramref name="size"/> using the specified /// <paramref name="textProvider"/>.</returns> public abstract override VerificationCodeImage GenerateAutoInputProtectionImage(string name, Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters);
/// <summary> /// 生成图像 /// </summary> /// <param name="size"></param> /// <param name="textProvider"></param> /// <param name="characterSet"></param> /// <param name="maximumCharacters"></param> /// <param name="minimumCharacters"></param> /// <returns></returns> public override VerificationCodeImage GenerateRandomAutoInputProtectionImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) { return(GenerateAutoInputProtectionImage(null, size, textProvider, characterSet, maximumCharacters, minimumCharacters)); }
/// <summary> /// 生成干扰图像 /// </summary> /// <param name="name"></param> /// <param name="size"></param> /// <param name="textProvider"></param> /// <param name="characterSet"></param> /// <param name="maximumCharacters"></param> /// <param name="minimumCharacters"></param> /// <returns></returns> public override VerificationCodeImage GenerateAutoInputProtectionImage(string name, Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) { LineNoiseVerificationCodeImage image = new LineNoiseVerificationCodeImage(size, textProvider, colors, characterSet, maximumCharacters, minimumCharacters); // code added after 1.0.0 RTW: if (Margin != -1) { image.Margin = Margin; } if (MinimumCharacterRotation != -1) { image.MinimumCharacterRotation = MinimumCharacterRotation; } if (MaximumCharacterRotation != -1) { image.MaximumCharacterRotation = MaximumCharacterRotation; } return(image); }
public LineNoiseVerificationCodeImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) : base(size, textProvider, characterSet, maximumCharacters, minimumCharacters) { colors = new List <Color>(1); colors.Add(Color.Black); }
protected BackgroundVerificationCodeImage(Size size, VerificationCodeTextProvider textProvider, CaptchaCharacterSet characterSet, int?maximumCharacters, int?minimumCharacters) : base(size, textProvider, characterSet, maximumCharacters, minimumCharacters) { }