search
HomeBackend DevelopmentC#.Net Tutorial.Net Core Graphic Verification Code

This article introduces the use of third-party ZKWeb.System.Drawing to implement the verification code function under .Net Core.

通过测试的系统:
Windows 8.1 64bit
Ubuntu Server 16.04 LTS 64bit
Fedora 24 64bit
CentOS 7.2 64bit

可以实现以下功能:
Open jpg, bmp, ico, png
Save jpg, bmp, ico, png
Resize image
Draw graphics with brush and pen
Open font and draw string

The above is the official information.

No.1 project introduces ZKWeb.System.Drawing

NuGet import package, which Baidu does not know how to do.

No.2 Simple verification code generation

int codeW = 80;
int codeH = 30;
int fontSize = 16;
Random rnd = new Random();
//颜色列表,用于验证码、噪线、噪点 
Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue };
//字体列表,用于验证码 
string[] font = { "Times New Roman" };
//验证码的字符集,去掉了一些容易混淆的字符 

//写入Session、验证码加密
//WebHelper.WriteSession("session_verifycode", Md5Helper.MD5(chkCode.ToLower(), 16));
//创建画布
Bitmap bmp = new Bitmap(codeW, codeH);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
//画噪线 
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);
}
//画验证码字符串 
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);
}
//将验证码图片写入内存流,并将其以 "image/Png" 格式输出 
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

Just go to the picture above, if you don’t know it, look here www.cnblogs.com/niao/p/6057860.html

.Net Core Graphic Verification Code

Note: There is no pressure to generate the verification code under Windows. I use Ubuntu 14 and need to install the gdi package. There will be a prompt in the running log.

Installation method:

Ubuntu 16.04:

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

Fedora 23:

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

CentOS 7:

yum install autoconf automake libtool
yum install freetype-devel fontconfig libXft-devel
yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
yum install glib2-devel cairo-devel
git clone https://github.com/mono/libgdiplus
cd libgdiplus
./autogen.sh
make
make install
cd /usr/lib64/
ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

[Related recommendations]

1. .NET Core configuration file loading and DI injection of configuration data

2. .NET Core CLI tool documentation dotnet-publish

3. Detailed introduction to ZKEACMS for .Net Core

4. Share the form verification example code in .net MVC

5. Under .net core How to make http request?

6. An example tutorial of running ZKEACMS on CentOS

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 Windows 11 中启用 Core Isolation 的内存完整性功能如何在 Windows 11 中启用 Core Isolation 的内存完整性功能May 10, 2023 pm 11:49 PM

Microsoft的Windows112022Update(22H2)默认启用CoreIsolation的内存完整性保护。但是,如果您运行的是旧版本的操作系统,例如Windows112022Update(22H1),则需要手动打开此功能。在Windows11中开启CoreIsolation的内存完整性功能对于不了解核心隔离的用户,这是一个安全过程,旨在通过将Windows上的基本核心活动隔离在内存中来保护它们免受恶意程序的侵害。该进程与内存完整性功能相结合,可确保

电脑core是什么意思电脑core是什么意思Sep 05, 2022 am 11:24 AM

电脑中core有两种意思:1、核心,也即内核,是CPU最重要的组成部分,CPU所有的计算、接受存储命令、处理数据都由核心执行;2、酷睿,core是英特尔的处理器名称,酷睿是英特尔公司继奔腾处理器之后推出的处理器品牌,目前已经发布了十二代酷睿处理器。

C#的就业前景如何C#的就业前景如何Oct 19, 2023 am 11:02 AM

无论您是初学者还是有经验的专业人士,掌握C#将为您的职业发展铺平道路。

分享几个.NET开源的AI和LLM相关项目框架分享几个.NET开源的AI和LLM相关项目框架May 06, 2024 pm 04:43 PM

当今人工智能(AI)技术的发展如火如荼,它们在各个领域都展现出了巨大的潜力和影响力。今天大姚给大家分享4个.NET开源的AI模型LLM相关的项目框架,希望能为大家提供一些参考。https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel是一种开源的软件开发工具包(SDK),旨在将大型语言模型(LLM)如OpenAI、Azure

如何修复 Windows 11 / 10 中的处理器热跳闸错误 [修复]如何修复 Windows 11 / 10 中的处理器热跳闸错误 [修复]Apr 17, 2023 am 08:13 AM

大多数设备(例如笔记本电脑和台式机)长期被年轻游戏玩家和编码人员频繁使用。由于应用程序过载,系统有时会挂起。这使用户被迫关闭他们的系统。这主要发生在安装和玩重度游戏的玩家身上。当系统在强制关闭后尝试启动时,它会在黑屏上抛出一个错误,如下所示:以下是在此引导期间检测到的警告。这些可以在事件日志页面的设置中查看。警告:处理器热跳闸。按任意键继续。..当台式机或笔记本电脑的处理器温度超过其阈值温度时,总是会抛出这些类型的警告消息。下面列出了在Windows系统上发生这种情况的原因。许多繁重的应用程序在

Java框架和.NET框架的性能差异Java框架和.NET框架的性能差异Jun 03, 2024 am 09:19 AM

在高并发请求处理方面,.NETASP.NETCoreWebAPI性能优于JavaSpringMVC,原因包括:AOT提前编译,减少启动时间;更精细的内存管理,由开发人员负责分配和释放对象内存。

面向开发人员的.NET性能优化技术面向开发人员的.NET性能优化技术Sep 12, 2023 am 10:43 AM

如果你是一名.NET开发者,你必须意识到在交付高质量软件方面,优化功能和性能的重要性。通过熟练使用提供的资源并减少网站加载时间,你不仅为用户创造了愉快的体验,还能减少基础设施成本。

CORE币值得长期持有吗?CORE币值得投资吗?CORE币值得长期持有吗?CORE币值得投资吗?Feb 29, 2024 pm 05:34 PM

CORE币:值得长期持有吗?CORE币是一个基于工作量证明(PoW)共识机制的加密货币,由Core团队在2018年创立。其目标是建立一种安全、高效、可扩展的数字货币体系,被广泛应用于支付和价值储存。CORE币的设计旨在提供一种去中心化的支付解决方案,为用户提供更多的隐私保护和交易便利性。CORE币的优势安全:CORE币基于工作量证明共识机制,具有很强的安全性。高效:CORE币的交易速度快,每秒可处理数千笔交易。可扩展:CORE币的区块容量大,可支持大量交易。去中心化:CORE币是一个去中心化的加

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment