. Net Core graphic verification code,. netcore

Source: Internet
Author: User

. Net Core graphic verification code,. netcore
This article describes how to use a third-party ZKWeb. System. Drawing in. Net Core to implement the verification code function.

Tested system: Windows 8.1 64 bitUbuntu Server 16.04 LTS 64 bitFedora 24 64 bitCentOS 7.2 64bit can implement the following functions: Open jpg, bmp, ico, pngSave jpg, bmp, ico, pngResize imageDraw graphics with brush and penOpen font and draw string

The above are official materials.

No.1 introduce ZKWeb. System. Drawing

NuGet introduces the package and won't be Baidu.

No. 2 simple verification code generation
Int codeW = 80; int codeH = 30; int fontSize = 16; Random rnd = new Random (); // color list, used for verification codes, noise lines, and noise Color [] color = {Color. black, Color. red, Color. blue, Color. green, Color. orange, Color. brown, Color. brown, Color. darkBlue}; // font list, used for verification code string [] font = {"Times New Roman"}; // Character Set of the verification code, some confusing characters are removed. // write Session and verification code encryption // WebHelper. writeSession ("session_verifycode", Md5Helper. MD5 (chkCode. toLower (), 16); // create the canvas Bitmap bmp = new Bitmap (codeW, codeH); Graphics g = Graphics. fromImage (bmp); g. clear (Color. white); // draw the noise line for (int I = 0; I <1; I ++) {int x1 = rnd. next (codeW); int y1 = rnd. next (codeH); int x2 = rnd. next (codeW); int y2 = rnd. next (codeH); Color clr = color [rnd. next (color. length)]; g. drawLine (new Pen (clr), x1, y1, x2, y2);} // draw the verification code string for (int I = 0; I <chkCode. length; I ++) {string fnt = font [rnd. next (font. length)]; Font ft = new Font (fnt, fontSize); Color clr = color [rnd. next (color. length)]; g. drawString (chkCode [I]. toString (), ft, new SolidBrush (clr), (float) I * 18, (float) 0);} // write the verification code image to the memory stream, and output MemoryStream MS = new MemoryStream (); try {bmp. save (MS, ImageFormat. png); return ms. toArray ();} catch (Exception) {return null;} finally {g. dispose (); bmp. dispose ();}
No. 3 release, deployment, and Operation

Directly, don't look at this http://www.cnblogs.com/niao/p/6057860.html

Note: There is no pressure to generate the verification code in Windows. For Ubuntu 14, we need to install the gdi package. A prompt is displayed in the running log.

Installation Method:

Ubuntu 16.04:

apt-get install libgdipluscd /usr/libln -s libgdiplus.so gdiplus.dll

 

Fedora 23:

dnf install libgdipluscd /usr/lib64/ln -s libgdiplus.so.0 gdiplus.dll

 

CentOS 7:

yum install autoconf automake libtoolyum install freetype-devel fontconfig libXft-develyum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-develyum install glib2-devel cairo-develgit clone https://github.com/mono/libgdipluscd libgdiplus./autogen.shmakemake installcd /usr/lib64/ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

 

 

88 ..

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.