delphi.net自动生成字体图片 如验证码 遇到难题 ( 积分: 100 )

  • 主题发起人 主题发起人 zhbf2000
  • 开始时间 开始时间
Z

zhbf2000

Unregistered / Unconfirmed
GUEST, unregistred user!
uses System.IO;
{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support --do
not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebForm1.InitializeComponent;
begin
Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}
procedure TWebForm1.Page_Load(sender: System.Object;
e: System.EventArgs);
var img :Bitmap;
gdiobj: Graphics;
ms : MemoryStream;
vfycode : String;
SessionKeyname:String;
pf: PointF;
// bmpdata:BitmapData;
begin
If assigned(Request.QueryString.Item['SessionKeyName']) then
begin
SessionKeyname := Request.QueryString.Item['SessionKeyName'].ToString.Trim;
if SessionKeyname<>'' then
begin
vfycode:='1234';
response.Cookies.Item['viewimg'].Item[SessionKeyname]:=vfycode;
img := System.Drawing.Bitmap.Create(32, 16);
gdiobj := Graphics.FromImage(img);
pf.X := 0;
pf.Y := 0;
gdiobj.DrawString(vfycode,Font.Create('Arial', 9), SolidBrush.Create(Color.white), pf);
ms := MemoryStream.Create();
[red]img.Save(ms,ImageFormat.Gif);这里为什么asp.net可以,delphi.net不可以运行[/red]
Response.ClearContent();
Response.ContentType := 'image/bmp';
Response.BinaryWrite(ms.ToArray());
end;
end;

Response.&
end;

end;
 
uses System.IO;
{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support --do
not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebForm1.InitializeComponent;
begin
Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}
procedure TWebForm1.Page_Load(sender: System.Object;
e: System.EventArgs);
var img :Bitmap;
gdiobj: Graphics;
ms : MemoryStream;
vfycode : String;
SessionKeyname:String;
pf: PointF;
// bmpdata:BitmapData;
begin
If assigned(Request.QueryString.Item['SessionKeyName']) then
begin
SessionKeyname := Request.QueryString.Item['SessionKeyName'].ToString.Trim;
if SessionKeyname<>'' then
begin
vfycode:='1234';
response.Cookies.Item['viewimg'].Item[SessionKeyname]:=vfycode;
img := System.Drawing.Bitmap.Create(32, 16);
gdiobj := Graphics.FromImage(img);
pf.X := 0;
pf.Y := 0;
gdiobj.DrawString(vfycode,Font.Create('Arial', 9), SolidBrush.Create(Color.white), pf);
ms := MemoryStream.Create();
[red]img.Save(ms,ImageFormat.Gif);这里为什么asp.net可以,delphi.net不可以运行[/red]
Response.ClearContent();
Response.ContentType := 'image/bmp';
Response.BinaryWrite(ms.ToArray());
end;
end;

Response.&
end;

end;
 
Bitmap在Delphi只是一个结构,如要用类可改用TBitmap。
 
后退
顶部