delphi 获取网络图片

2018-10-30

代码文件:
--------------------------------------------------------------------------------

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses jpeg;

procedure TForm1.Button1Click(Sender: TObject);
const
url = 'http://ptlogin2.qq.com/getimage?aid=15000701&0.9129723031485226';
var
ms: TMemoryStream;
jpg: TJPEGImage;
begin
ms := TMemoryStream.Create;
jpg := TJPEGImage.Create;

IdHTTP1.Get(url, ms);
ms.Position := 0;

jpg.LoadFromStream(ms);
Canvas.Draw(10, 10, jpg);

jpg.Free;
ms.Free;
end;

end.
阅读117