> 백엔드 개발 > C#.Net 튜토리얼 > .Net 핵심 그래픽 확인 코드

.Net 핵심 그래픽 확인 코드

高洛峰
풀어 주다: 2017-05-26 13:32:01
원래의
3321명이 탐색했습니다.

이 기사에서는 타사 ZKWeb.System. Drawing을 사용하여 .Net Core에서 인증 코드 기능을 구현하는 방법을 소개합니다.

1

2

3

4

5

6

7

8

9

10

11

12

通过测试的系统:

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

로그인 후 복사

위 내용은 공식정보입니다.

No.1 프로젝트에서 ZKWeb.System.드로잉을 소개합니다

NuGet 가져오기 패키지, Baidu는 어떻게 하는지 모릅니다.

No.2 간편인증코드 생성

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

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 게시, 배포, 실행

사진 바로 위, 방법을 모르신다면 보세요 여기 www.cnblogs.com/ niao/p/6057860.html

.Net 핵심 그래픽 확인 코드

참고: 저는 Ubuntu 14를 사용하므로 인증 코드를 생성해야 한다는 압박감은 없습니다. gdi 패키지를 설치하면 작업 로그에 프롬프트가 표시됩니다.

설치 방법:

Ubuntu 16.04:

1

2

apt-get install libgdiplus

cd /usr/libln -s libgdiplus.so gdiplus.dll

로그인 후 복사

Fedora 23:

1

2

dnf install libgdiplus

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

로그인 후 복사

CentOS 7:

1

2

3

4

5

6

7

8

9

10

11

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

로그인 후 복사

[관련 권장 사항]

1. .NET Core 구성 파일 로딩 및 구성 데이터 DI 삽입

2.NET Core CLI 도구 설명서 dotnet- 게시

3.

.Net Core용 ZKEACMS 자세히 소개

4.

.net MVC의 양식 확인 예제 코드 공유

5.

.net 코어에서 http 요청을 만드는 방법은 무엇입니까?

6.

CentOS에서 ZKEACMS 실행 인스턴스 튜토리얼

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿