This article introduces the implementation of ASP. NET picture Verification code, the code is easy to understand, very good, with reference value, the need for reference of friends
Context. Response.ContentType = "Image/jpeg"; Generate random Chinese verification code String Yzm = "Population hand size how much upper and lower men and women Heaven anti-Qing Yang Zhengko Small Baodire namespace language now come to me more than one tomorrow Shandong Hebei South Gu ' an Beijing Nanchang Donghassian is Shahe Higher Education Park Science" + "Wood wo up and down soil eight into the great Heaven Fire six or seven son nine no Mouth Sub-door month does not open four or five head meter see white field electric also Chang-fei horse bird cloud bus cow sheep small towel teeth foot hair and heart hand Huang foot "+" walk side half bar industry Motohira book Self things back piece rawly fruit several with fish this is rain two melon clothing next year around hundred Dinzidong said friends Chun Gao you green, grass, the old line of the year of the age of the ancient sound know more busy wash true recognition Father sweep "+ "Mom and Dad write the whole closed home to see a smile xing painting will mother milk put girly too early to light and Li Yuxiu thousand fragrant listen to sing to even more after the master always start dry Ming catch net with special work class team ant anterior chamber Empty network poem Huang Lin closed" + " Dongli is my leaf beauty machine she sent it to him when he gave it to the worm is the river borrow elder sister Ah, who is afraid of the amount with the most garden face because Yang for the Guangkofa find do not let that to all scare to do like a point like the sand sand Bridge Army bamboo seedling well face township "+" Forget to miss the king this from the edge of the shell of the male love shrimp run music to the old Quick Division short light on the hot cold love pull live to eat practice study non-bitter often ask companion want No child to choose north Hunan Autumn River only help star please snow ball jump play "+" peach just blue seat each belt sit urgent name hair into move late new have to change what article "; Random r = new Random (); String validcode = ""; for (int i = 0; i < 4; i++) {int number = R.next (0, Yzm. Length); Validcode + = Yzm[number]; }//Paint using (Bitmap B = new Bitmap ()) {using (Graphics g = graphics.fromimage (b)) using (Font F = new F Ont ("Arial")) {g.clear (Color.yellow);//clear the entire drawing face and fill the specified background color g.drawstring (Validcode, F, brushes.red, new PointF (0, 0)///Start drawing//Pre-attraction for (int i = 0; i < i++) { int x = r.next (0, 150); int y = r.next (0, 30); B.setpixel (x, y, color.red); }//Background line for (int i = 0; i <; i++) {int x = r.next (0, 150); int y = r.next (0, 30); G.drawline (pens.red, x, y, x + 1, y + 1); }} b.save (context. Response.outputstream, imageformat.jpeg);//save to output stream}
"Recommended"
1. asp free Video Tutorial
2. Eon the ASP Basic video tutorial
3. asp Tutorials