Delphi 模拟网站验证码(酷,把随机文字写道图片上)
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi 模拟网站验证码(酷,把随机文字写道图片上)相关的知识,希望对你有一定的参考价值。
- function TfrmLabelPages.PwdImg(img: Timage): string;
- var
- I,j,k: Integer;
- vPoint: TPoint;
- vLeft: Integer;
- arrStr:array [1..36]of string ;
- strResult: string;
- begin
- strResult := ‘‘;
- arrStr[1] := ‘0‘; arrStr[2]:=‘1‘; arrStr[3]:=‘2‘; arrStr[4]:=‘3‘;
- arrStr[5] := ‘4‘; arrStr[6]:=‘5‘; arrStr[7]:=‘6‘; arrStr[8]:=‘7‘;
- arrStr[9] := ‘8‘; arrStr[10]:=‘9‘; arrStr[11]:=‘A‘; arrStr[12]:=‘B‘;
- arrStr[13] := ‘C‘; arrStr[14]:=‘D‘; arrStr[15]:=‘E‘; arrStr[16]:=‘F‘;
- arrStr[17] := ‘G‘; arrStr[18]:=‘H‘; arrStr[19]:=‘I‘; arrStr[20]:=‘J‘;
- arrStr[21] := ‘K‘; arrStr[22]:=‘L‘; arrStr[23]:=‘M‘; arrStr[24]:=‘N‘;
- arrStr[25] := ‘O‘; arrStr[26]:=‘P‘; arrStr[27]:=‘Q‘; arrStr[28]:=‘R‘;
- arrStr[29] := ‘S‘; arrStr[30]:=‘T‘; arrStr[31]:=‘U‘; arrStr[32]:=‘V‘;
- arrStr[33] := ‘W‘; arrStr[34]:=‘X‘; arrStr[35]:=‘Y‘; arrStr[36]:=‘Z‘;
- For j:=1 to 4 do
- begin
- Randomize;
- k := strtoint(Format(‘%.1d‘,[Random(36)]));
- strResult := strResult + trim(arrStr[k])
- end;
- vLeft := 10;
- img.picture := nil;
- for I := 1 to Length(strResult) do
- begin
- with Img do
- begin
- Canvas.Font.Size := Random(10)+ 9;
- Canvas.Font.Color := RGB(Random(256) and $C0,
- Random(256) and $C0, Random(256) and $C0);
- if Random(2)=1 then
- Canvas.Font.Style := [fsBold]
- else Canvas.Font.Style := [];
- begin
- Canvas.Font.Name := Screen.Fonts[10];
- vPoint.X := Random(4)+ vLeft;
- vPoint.Y := Random(5);
- Canvas.TextOut(vPoint.X, vPoint.Y,strResult[I]);
- vLeft := vPoint.X + Canvas.TextWidth(strResult[I]);
- end;
- end;
- end;
- end;
http://blog.csdn.net/yanjiaye520/article/details/7957397
以上是关于Delphi 模拟网站验证码(酷,把随机文字写道图片上)的主要内容,如果未能解决你的问题,请参考以下文章