难题:如果保存WEBBROWSER里的一个图片到IMAGE控件里 ( 积分: 150 )

  • 主题发起人 主题发起人 robert168
  • 开始时间 开始时间
R

robert168

Unregistered / Unconfirmed
GUEST, unregistred user!
网址:passport.csdn.net
问题:我想通过webbrowser打开该页面,然后通过技术手段把该页面中的验证码保存到一个image控件里去.
难点:1)该验证码图片在临时文件夹里根本就找不到
2)该验证码动态生成,执行一次就改变一次,前次的将失效.
 
[?][?][?][?][?]
 
全世界最简单的办法:丢个TIdThreadComponent控件,然后在onrun里写线程代码就行了。我用这控件开了几百个线程做了个聊天服务器。
 
有源代码吗?可以发给我吗? robert888888@hotmail.com
我没写过,想学下,想从实例入手,这样更快点.
 
靠,这还要源代码?直接双击控件的onrun事件,在里面写你的线程执行代码就行了
 
我要知道这么多还发贴干什么
不愿帮忙就别搅局了
 
以前写的一段代码,可以参考一下,确实不复杂的。
unit DownThread;

interface

uses
Classes, SysUtils, IdComponent, IdHTTP;

type
TEventType = (etStatus, etWork, etWorkBegin, etWorkEnd);
TDTCallBackEvent = procedure(AThreadID: THandle; AEventType: TEventType; AThreadInfo: string) of object;
TDownThread = class(TThread)
private
FFileUrl: string;
FFileSaveName: string;
FDTCallBackEvent: TDTCallBackEvent;
FEventType: TEventType;
FThreadInfo: string;
procedure HTTPStatus(axSender: TObject; const axStatus: TIdStatus;
const asStatusText: string);
procedure HTTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure HTTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure HTTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure DoDTCallBackEvent(AEventType: TEventType; AThreadInfo: string);
procedure DoCallBack;
public
constructor Create(AFileUrl, AFileSaveName: string; CreateSuspended: Boolean = False);
procedure Execute; override;
property DTCallBackEvent: TDTCallBackEvent read FDTCallBackEvent write FDTCallBackEvent;
end;

implementation

{ TDownThread }

constructor TDownThread.Create(AFileUrl, AFileSaveName: string;
CreateSuspended: Boolean);
begin
FFileUrl := AFileUrl;
FFileSaveName := AFileSaveName;
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;

procedure TDownThread.DoCallBack;
begin
if Assigned(FDTCallBackEvent) then
FDTCallBackEvent(Handle, FEventType, FThreadInfo);
end;

procedure TDownThread.DoDTCallBackEvent(AEventType: TEventType; AThreadInfo: string);
begin
FEventType := AEventType;
FThreadInfo := AThreadInfo;
SYNCHRONIZE(DoCallBack);
end;

procedure TDownThread.Execute;
var
Stream: TStream;
begin
Stream := TFileStream.Create(FFileSaveName, fmCreate);
try
with TIdHTTP.Create(nil) do
try
OnStatus := HTTPStatus;
OnWork := HTTPWork;
OnWorkBegin := HTTPWorkBegin;
OnWorkEnd := HTTPWorkEnd;
Get(FFileUrl, Stream);
finally
Free;
end;
finally
Stream.Free;
end;
end;

procedure TDownThread.HTTPStatus(axSender: TObject;
const axStatus: TIdStatus; const asStatusText: string);
begin
DoDTCallBackEvent(etStatus, asStatusText);
end;

procedure TDownThread.HTTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
DoDTCallBackEvent(etWork, IntToStr(AWorkCount));
end;

procedure TDownThread.HTTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
DoDTCallBackEvent(etWorkBegin, IntToStr(AWorkCountMax));
end;

procedure TDownThread.HTTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
DoDTCallBackEvent(etWorkEnd, Format('任务完成:(%s ==> %s)', [FFileUrl, FFileSaveName]));
end;

end.

调用:
procedure TFormMain.Button2Click(Sender: TObject);
begin
with TDownThread.Create(Edit1.Text, Edit2.Text, True) do
begin
//DTCallBackEvent := ThreadStatus;
Resume;
end;
end;
 
多人接受答案了。
 
后退
顶部