In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to create bitmaps to generate and verify picture classes in asp.net". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The copy code is as follows:
Public void ProcessRequest (HttpContext context)
{
Context.Response.ContentType = "image/jpeg"
/ / create a bitmap and specify the width and height of the frame
Using (Image img=new Bitmap (800.25))
{
/ / create a painter object and draw a string in the img object
Using (Graphics g=Graphics.FromImage (img))
{
/ / sets the background color of the bitmap. The default is black.
G.Clear (Color.White)
/ / set the width and height of the CAPTCHA. Img.Width-1 and img.Height-1 mainly cover the border with the background color.
G.DrawRectangle (Pens.Black, 0,0, img.Width-1, img.Height-1)
/ / transfer 100 noises, painter objects, bitmap objects
DrawPoint (100g, img)
/ / draw a string of 4 CAPTCHA codes
String vcode=GetCode (4); / / vcode can be assigned to Cookie here
G.DrawString (vcode
New Font ("Arial", 14, FontStyle.Strikeout | FontStyle.Strikeout), / / FontStyle font style, multiple styles are required | Line
Brushes.Black
New RectangleF (r.Next (20), r.Next (7), img.Width, img.Height))
Img.Save (context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); / / Save the CAPTCHA object, specified in Jpeg format
}
}
}
/ / method of drawing noise
Void DrawPoint (int point,Graphics grecently Image img)
{
For (int I = 0; I < point; iTunes +)
{
Int x = r.Next (img.Width)
Int y = r.Next (img.Width)
G.DrawLine (Pens.Red
New Point (x, y)
New Point (Xerox 2, YF2))
}
}
/ / Random number
Random r = new Random ()
/ / character creation
String GetCode (int point)
{
String txtStr = "ASF2345WE5R9F3HMBCZ455K"; / / the string string here will be converted into an char array, and the Arabic numeral 1 and the lowercase l had better not be written in it, it will be messy.
Char [] charArr = txtStr.ToArray ()
Int num = 0
String code = ""
For (int I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.