获取指定地址的 JPG 图片 - 回复 "bangrj" 的问题


问题来源: http://www.cnblogs.com/del/archive/2009/02/27/1370907.html#1463071

本例效果图:

获取指定地址的 JPG 图片 - 回复 "bangrj" 的问题

代码文件:

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.


 
   

窗体文件:

object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 126

  ClientWidth = 158

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 40

    Top = 88

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 0

    OnClick = Button1Click

  end

  object IdHTTP1: TIdHTTP

    AllowCookies = True

    ProxyParams.BasicAuthentication = False

    ProxyParams.ProxyPort = 0

    Request.ContentLength = -1

    Request.Accept = 'text/html, */*'

    Request.BasicAuthentication = False

    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'

    HTTPOptions = [hoForceEncodeParams]

    Left = 8

    Top = 8

  end

end


 
   

你可能感兴趣的:(jpg)