delphi验证码图像生成,修改自“名士:517165547”

function GenerateVerifyCode(var code:string):TBitmap;
var
I,j,k: Integer;
vPoint: TPoint;
vLeft: Integer;
arrStr:array [1..36]of string ;
vcodebmp:TBitmap;
pwdimgstr:string;
begin
pwdimgstr:=‘‘;
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)]));
pwdimgstr:=pwdimgstr+trim(arrStr[k])
end;
vLeft:=10;
vcodebmp:=TBitmap.Create;
vcodebmp.Width:=73;
vcodebmp.Height:=25;

for I:= 1 to Length(pwdimgstr) do
begin
with vcodebmp 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,pwdimgstr[I]);
vLeft := vPoint.X + Canvas.TextWidth(pwdimgstr[I]);
end;
end;
end;
code:=pwdimgstr;
Result:= vcodebmp;

end;

 

delphi验证码图像生成,修改自“名士:517165547”

上一篇:Linux用户增删改查


下一篇:linux磁盘清理方法 Linux 下垃圾清理工具 BleachBit