标题:随机生成验证码的一个演示升级版+++
只看楼主
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
结帖率:97.44%
已结贴  问题点数:20 回复次数:13 
随机生成验证码的一个演示升级版+++
上次做的是直接在form上画,运行速度有点慢,现在改成在内存上,速度就快多了,而且生成的验证码图片,用上次吹水佬的二极化代码无法彻底去噪

附上代码,有兴趣的可以提高一下二极化的代码算法。。。

程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


    **************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\logondemo.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   10/23/22 09:00:05 PM
*
DEFINE CLASS form1 AS form


    DoCreate = .T.
    AutoCenter = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT label1 AS label WITH ;
        Caption = "用户名", ;
        Height = 16, ;
        Left = 110, ;
        Top = 30, ;
        Width = 38, ;
        Name = "Label1"


    ADD OBJECT text1 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 26, ;
        Width = 100, ;
        Name = "Text1"


    ADD OBJECT label2 AS label WITH ;
        Caption = "密  码", ;
        Height = 16, ;
        Left = 110, ;
        Top = 60, ;
        Width = 38, ;
        Name = "Label2"


    ADD OBJECT text2 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 56, ;
        Width = 100, ;
        PasswordChar = "*", ;
        Name = "Text2"


    ADD OBJECT label3 AS label WITH ;
        Caption = "验证码", ;
        Height = 16, ;
        Left = 110, ;
        Top = 90, ;
        Width = 38, ;
        Name = "Label3"


    ADD OBJECT text3 AS textbox WITH ;
        Height = 20, ;
        Left = 160, ;
        Top = 85, ;
        Width = 100, ;
        Name = "Text3"


    ADD OBJECT label4 AS label WITH ;
        AutoSize = .T., ;
        Caption = "点击显示验证码", ;
        Height = 16, ;
        Left = 100, ;
        Top = 128, ;
        Width = 86, ;
        Name = "Label4"


    ADD OBJECT image1 AS image WITH ;
        Height = 80, ;
        Left = 100, ;
        Top = 148, ;
        Width = 180, ;
        Name = "Image1"


    PROCEDURE image1.Init
        this.click
    ENDPROC


    PROCEDURE image1.Click
        thisform.Cls()
        RAND(-1)

        *****************************生成随机干扰码*************************************
        SET CLASSLIB TO HOME()+"FFC\_gdiplus.vcx"
        locolor=CREATEOBJECT("gpcolor",255,255,255,255)
        lobrush=CREATEOBJECT("gpsolidbrush",locolor)
        lographics=CREATEOBJECT("gpgraphics")
        lobitmap=CREATEOBJECT("gpbitmap",this.Width,this.height)
        lographics.createfromimage(lobitmap)
        lographics.fillrectangle(lobrush,0,0,this.width,this.height)
        FOR i=1 TO 150
            lncolor=INT(RAND()*1000000)
            nred=MOD(lncolor,0x100)
            ngreen=INT(MOD(lncolor,0x10000)/0x100)
            nblue=INT(lncolor/0x10000)
            locolor.set(nred,ngreen,nblue,255)
            lobrush.create(locolor)
            DO WHILE .t.
                nleft=INT(RAND()*200)
                ntop=INT(RAND()*100)
                IF nleft<this.Width-5 AND ntop<this.Height-5
                    EXIT
                ELSE
                    loop
                ENDIF
            ENDDO
            lographics.fillrectangle(lobrush,nleft,ntop,5,5)
        ENDFOR 
        *****************************生成随机干扰码*************************************

        *****************************生成随机验证码*************************************
        lpString = randomstr(4)
        FOR i=1 TO 4
            nleft=40*(i-1)
            ntop=10
            lopoint=CREATEOBJECT("gppoint",nleft,ntop)
            lofont=CREATEOBJECT("gpfont")
            lofont.create("arial",32,0,3)
            lncolor=INT(RAND()*1000000)
            nred=MOD(lncolor,0x100)
            ngreen=INT(MOD(lncolor,0x10000)/0x100)
            nblue=INT(lncolor/0x10000)
            locolor.set(nred,ngreen,nblue,255)
            lobrush=CREATEOBJECT("gpsolidbrush",locolor)
            lostringformat=CREATEOBJECT("gpstringformat")
            lographics.drawstringA(SUBSTR(lpstring,i,1),lofont,lopoint,lostringformat,lobrush)
        ENDFOR 
        *****************************生成随机验证码*************************************

        lobitmap.savetofile("background.jpg","image/jpeg","quality=100")
        this.picture="background.jpg"
        RELEASE ALL LIKE lo
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************


运行效果图如下:


二级化效果图如下:
搜索更多相关主题的帖子: Name Left Top INT WITH 
2022-10-23 21:17
schtg
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:https://t.me/pump_upp
等 级:贵宾
威 望:67
帖 子:1355
专家分:2534
注 册:2012-2-29
得分:0 
谢谢分享!
2022-10-24 06:02
nbwww
Rank: 6Rank: 6
等 级:贵宾
威 望:10
帖 子:222
专家分:468
注 册:2021-1-9
得分:0 
2022-10-24 18:18
foxfans
Rank: 4
等 级:贵宾
威 望:11
帖 子:90
专家分:278
注 册:2021-10-23
得分:0 
很不错 加油
https://     这里Gdi+应用例子丰富,可以借鉴。


[此贴子已经被作者于2022-10-25 09:44编辑过]

2022-10-24 21:30
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
回复 楼主 sam_jiang
好,很象色盲检测卡。
2022-10-25 07:25
easyppt
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:119
专家分:169
注 册:2021-11-24
得分:0 
lpString = randomstr(4)   这句提示 过程不存在
2022-10-25 08:38
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 4楼 foxfans
可以把这个整体搬迁到gitee或者蓝奏吗?那个github网页我永远都是打不开的。
2022-10-25 16:15
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 5楼 吹水佬
哈哈哈,好像是有点像色盲检测卡,好像给我指明了另一个拓展方向。。。
2022-10-25 16:16
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
回复 6楼 easyppt
我上次那个贴子里有代码,所以这次没有把它发上来。

再发一下吧:
PARAMETERS tnlength   
LOCAL lcText, lcChar, x, n
lcText = ""
FOR n = 1 TO tnLength
    x = INT(RAND() * 36)
    lcChar = IIF(x < 10, TRANSFORM(x), CHR(x + 55))
    lcText = lcText + lcChar
ENDFOR
RETURN lcText
2022-10-25 16:18
sam_jiang
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:542
专家分:781
注 册:2021-10-13
得分:0 
好像可以对抗很多的文字识别软件,2345软件也识别不了!

2022-10-25 16:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510425-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028312 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved