- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 下载并显示网上的图片
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI, UrlMon;
procedure TForm1.Button1Click(Sender: TObject);
const
TestPath = 'c:\temp\net.gif'; {下载后临时存放}
DownUrl = 'http://del.cnblogs.com/Images/xml.gif'; {要下载的文件}
var
img: TGPImage;
g: TGPGraphics;
begin
if UrlDownloadToFile(nil, DownUrl, TestPath, 0, nil) = 0 then
begin
img := TGPImage.Create(TestPath);
g := TGPGraphics.Create(Canvas.Handle);
g.DrawImage(img, 10, 10, img.GetWidth, img.GetHeight);
g.Free;
img.Free;
end;
end;
end.