How to make Captcha in unigui?

墨蓝 2021-11-22 16:04 369阅读 0赞

unit UniCaptcha;

interface
uses
classes,
Graphics,
uniImage;

type TUniCaptcha=class(TUniImage)
private
FChallenge:ShortString;
procedure Render;
public
constructor create(Owner:TComponent);override;
procedure SetChallenge(aChallenge :ShortString);
published
property Challenge :ShortString read FChallenge write FChallenge;
end;

procedure Register;

implementation

constructor TUniCaptcha.Create(Owner:TComponent);
begin
inherited;
end;

procedure TUniCaptcha.SetChallenge(aChallenge:ShortString);
begin
FChallenge:= aChallenge;
Render;
end;

procedure TUniCaptcha.render;
Var
b :TBitmap;
i :Integer;
begin
b :=TBitmap.Create;
with b do
begin
b.Width :=self.Width;
b.height :=self.Height;
For i :=0 to 30dobegin
randomize;
canvas.Pen.Width := random(5)+5;
Canvas.Pen.Color := random(64738)+64738;
Canvas.Brush.Style := bsFDiagonal;

  1. Canvas.Ellipse(random(width),random(Height),random(width),random(height));
  2. end;
  3. Canvas.Font.Color:= clBlue;
  4. Canvas.Font.Size :=18;
  5. Canvas.TextOut(10,trunc(self.height/2),FChallenge);
  6. Canvas.Font.Color:= clRed;
  7. Canvas.TextOut(8,trunc(self.height/2)-2,FChallenge);

end;

Picture.Assign(B);
b.Free;
end;

procedure Register;
begin
RegisterComponents(‘UniCustom’,[TUniCaptcha]);
end;

end.

转载于:https://www.cnblogs.com/wxb-km/archive/2012/11/05/2755980.html

发表评论

表情:
评论列表 (有 0 条评论,369人围观)

还没有评论,来说两句吧...

相关阅读