/// <summary> /// Initialize a instance of ImageVerificationCodeResult class. /// </summary> /// <param name="code"></param> /// <param name="format"></param> /// <exception cref="System.ArgumentException"><paramref name="code"/> is null.</exception> public ImageVerificationCodeResult(ImageVerificationCode code) { if (code == null) { throw new ArgumentNullException("code"); } this.Code = code; }
public void GenerateTest() { List <char> characters = new List <char>(); for (char c = '0'; c <= '9'; c++) { characters.Add(c); } for (char c = 'a'; c <= 'z'; c++) { characters.Add(c); } for (char c = 'A'; c <= 'Z'; c++) { characters.Add(c); } characters.AddRange(new char[] { '#', '$', '%', '&', '*', }); RandomImageVerificationCodeOption option = new RandomImageVerificationCodeOption { BackgroundColors = new Color[] { Color.White, Color.Gray, Color.LightGray }, ForegroundColors = new Color[] { Color.Black, Color.Red, Color.Blue, Color.Yellow, Color.Orange }, CanvasWidth = new Range(100, 50), CanvasHeight = new Range(40, 20), FontSize = new Range(15, 10), //FontFamilies = new InstalledFontCollection().Families, FontFamilies = new FontFamily[] { new FontFamily("Arial") }, //FontStyles = new FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Underline }, FontStyles = new FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic }, MaxRotationDegree = 45, }; RandomImageVerificationCodeGenerator target = new RandomImageVerificationCodeGenerator(new RandomCharacterImageVerificationCodeValueProvider(new RandomCharacterVerificationCodeValueOption { CharactersCount = new Range(4, 4), Characters = characters, }), option); string name = null; ImageVerificationCode code = null; for (int i = 0; i < 100; i++) { code = target.Generate(); name = Guid.NewGuid().ToString(); code.Save(name + ".png"); File.WriteAllText(name + ".txt", code.Value, Encoding.UTF8); } }