Implementation Code for drawing a graphic verification code in ASP. NET, asp.net Verification Code

Source: Internet
Author: User

Implementation Code for drawing a graphic verification code in ASP. NET, asp.net Verification Code

This article will share with you a piece of asp.net code to implement the graphic verification code function, the code is simple and easy to understand, the specific code is as follows:

Context. response. contentType = "image/jpeg "; // generate a random Chinese verification code string yzm = "population, hands size, upper, lower, middle, and lower places, heaven and earth will reverse Qing dynasty, Fu ming, Yang zhongke, Xiao Bao, Shuang 'er namespace xi'an is the shahe High Education Park "+" Mu he up and down the earth eight into the big fire text six seven children nine loose days of the sub-door month don't open four or five Eyes Ears head rice see white field electric also Changshan out flying Horse, bird, cloud bus, cattle, sheep, small towel, teeth, feet, hair, heart, hand, water, wide upgrade, foot "+" take the square half Ba industry, this book, your own things back to the skin, fruit, a few fish, rain two melon clothing around the next year, Ding Qi Dong said friends spring friends high you green flowers red grass ye Jie's old line of the ancient sound zhiduo busy wash really read father sweep "+" Mother dad write all when you finish watching the shopping carnival, you will see the music of your mom and milk. When you get the girl's breath in the afternoon, you will go to the morning to shine and Li yuxiu Qianxiang to listen to the music and decide to connect to the Lord first. ai-level team: ant's front chamber, Kong, Wangshi, huanglin, "+" Tong Li: I am ye Meiji. Did she send me a video when she passed him? Well, the insects are very busy. Who is it? cool fear volume and the most garden face because Yang is light can fa shi to find do Xu BIE that all scared and want to make another image like sha Hai Qiao Jun Zhu Miao Jing Xiang "+" forget to Miss Wang this from the edge of the road, Bei male, the original love shrimp, run and play the old fast teacher, short light, to the hot and cold feelings, pull the live to give training, learning, not bitter, often asked with a group of steam points to have no children select north Hunan Qiu Jiang to help the stars to invite the snow to jump the ball to play "+" Peach Tree ganglan seat all sit in an emergency name turned into a new late what is changing "; random r = new Random (); string validCode = ""; for (int I = 0; I <4; I ++) {int number = r. next (0, yzm. length); validCode + = yzm [number];} // drawing using (Bitmap B = new Bitmap (150, 30) {using (Graphics g = Graphics. fromImage (B) using (Font f = new Font ("", 20) {g. clear (Color. yellow); // clear the entire painting surface and fill in the specified background color g. drawString (validCode, f, Brushes. red, new PointF (0, 0); // start to draw // foreground point for (int I = 0; I <100; I ++) {int x = r. next (0,150); int y = r. next (0, 30); B. setPixel (x, y, Color. red);} // The back scene line for (int I = 0; I <100; 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 it to the output stream}

Refer:

Asp.net methods for generating verification codes (1)

Implementation of webform image watermark and image verification code based on Asp.net

The above is a small series of ASP. NET image verification code, hope to help you, if you have any questions, please leave a message, xiaobian will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.