. 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 ..