用delphi怎么生成验证码的图片?

解决方案 »

  1.   

    这个一张图,实际上也可以由N个部分组成,其实就是拼凑.
    Canvas.Draw(X, Y,Graphic)就可以指定位置画图.比如12这个数字,先画1,然后在1的后面位置画2就OK.
      

  2.   

    to fbysss(独孤求败)能不能给个大概的例子?
    比如我要在Form1上,点击Button1生成一个验证马图片,是4位数字的
      

  3.   

    下午也忙,随便写了一个,你看看吧,应该明白的.
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Image1: TImage;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    const
    PicWidth = 12;//每个数字图片的宽度
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,iNum,iLen : integer;
      sNum,sPath : string;
      bmp : TBitmap;
    begin
      iNum:= 1234;
      sNum := IntToStr(iNum);
      sPath := 'C:\pic\';
      iLen := Length(sNum);
      bmp := TBitmap.Create;
      try
        for i := 1 to iLen do
        begin
          with Image1.Canvas do
          begin        bmp.LoadFromFile(sPath+sNum[i]+'.bmp');
            Draw(i*PicWidth,0,bmp);
          end;
        end;
      finally
        bmp.Free;
      end;
    end;end.
      

  4.   

    //随机大法~~
    procedure TForm1.Button1Click(Sender: TObject);
    var
      S: string;
      I: Integer;
      vPoint: TPoint;
      vLeft: Integer;
    begin
      Randomize;
      S := Format('%.4d', [Random(10000)]);
      vLeft := 0;
      Canvas.FillRect(Canvas.ClipRect);
      for I := 1 to Length(S) 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 := [];
        Canvas.Font.Name := Screen.Fonts[10];
        vPoint.X := Random(4) + vLeft;
        vPoint.Y := Random(10);
        Canvas.TextOut(vPoint.X, vPoint.Y, S[I]);
        vLeft := vPoint.X + Canvas.TextWidth(S[I]);
      end;
    end;