首页
社区
课程
招聘
[旧帖] [求助]用C++编程,下载网页验证码并保存为图片 0.00雪花
2010-12-3 08:37 1282

[旧帖] [求助]用C++编程,下载网页验证码并保存为图片 0.00雪花

2010-12-3 08:37
1282
用winsock下收到的验证码图片数据是什么格式,并如何保存图片。求助源码提示。谢谢!!

[培训]《安卓高级研修班(网课)》月薪三万计划,掌 握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
点赞0
打赏
分享
最新回复 (2)
雪    币: 52
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
jdss 2010-12-3 13:54
2
0
最近也开始研究验证码了。。delphi写的。。
//拍拍抢购http://captcha.paipai.com/getimage
//http://captcha.qq.com/getimage
//http://www.51.la/user/vcode.asp
function DownLoadOCRCode(const imgURL:pchar):TBitmap;stdcall;
  function parseurldirectory(const imgURL:pchar):pchar;
  var
   pctmp:pchar;
   btmp:Byte;
   destination:Pchar;

  begin
    Result := '';
    btmp:= Pos('.',imgURL);
    pctmp:=pchar(Copy(imgURL,btmp+1,length(imgURL)-btmp));
    btmp:= Pos('.',pctmp);
    pctmp:=pchar(Copy(pctmp,1,btmp-1));
    strcopy(destination,pctmp);   //不加这句话,直接result:=pctmp 时候 当目录名是数字51的时候,返回的空乱码?
     //showmessage(strpas(sDesti));
    Result := destination;
  end;

  function GetImgStyleFromSteam(const Stream:TMemoryStream):Pchar;
  var
    buffer:word;
    imgStyle:pchar;
    imgStream:TMemoryStream;
  begin
    Result := '';
    try
      imgStream := TMemoryStream.Create;
      imgStream.LoadFromStream(stream);
      imgStream.Position := 0;
      if imgStream.Size = 0 then exit;
      imgStream.ReadBuffer(buffer,2);
      case buffer of
        $4D42:imgStyle:='.bmp';
        $D8FF:imgStyle:='.jpeg';
        $4947:imgStyle:='.gif';
        $5089:imgStyle:='.png';
      end;
    finally
      imgStream.Free;
    end;
    Result := imgStyle;
  end;
Var
  imgStream:TMemoryStream;
  _Http:TidHttp;
  imgDirectory:Pchar;
  bitmap:TBitmap;
  jpeg:TJpegimage;
  buffer:word;
  imgStyle:pchar; //文件类型 BMP JPG PNG等
begin
  Result:=nil;
  try
    bitmap := TBitmap.Create;
    imgStream:=TMemoryStream.Create;
    try
      _Http    := TIdhttp.Create(nil);
      _Http.Get(imgURl,imgStream);

      imgStyle:=GetImgStyleFromSteam(imgStream);
      if imgStyle = '.jpeg' then
      begin
        jpeg:= Tjpegimage.Create;
        imgStream.Position := 0;
        jpeg.LoadFromStream(imgStream);
        bitmap.Assign(jpeg);
        jpeg.Free;
      end
      else if imgStyle = '.bmp' then
      begin
        imgStream.Position := 0;
        bitmap.LoadFromStream(imgStream);
      end;
      imgDirectory :=parseurlDirectory(imgURL);     //图片目录
      if  imgDirectory <> '' then
      begin
        imgDirectory:=pchar(ExtractFilePath(paramstr(0))+ strpas(imgDirectory));
        if not DirectoryExists(imgDirectory) then CreateDir(imgDirectory);
        bitmap.SaveToFile(imgDirectory+'\'+formatdatetime('yyyy-mm-dd hh-mm-ss',now)+'.bmp');
        Result:= Tbitmap.Create;
        Result:=bitmap;
      end;  
    except
      On E:Exception do
      begin
         Result:= nil;
      end;
    end;
  finally
    imgStream.Free;
    _Http.Free;
    //bitmap.Free;
  end;
end;
雪    币: 40
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
skyxskyx 2010-12-3 15:02
3
0
有个win32 API: URLDownloadTOFile(url...) 保存为文件
游客
登录 | 注册 方可回帖
返回