问题来源: http://www.cnblogs.com/del/archive/2008/11/25/1339604.html#1381839

方法1: 用 TImage
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Image1.Align := alClient;
  Image1.Stretch := True;
  Image1.Picture.LoadFromFile('c:\temp\test.bmp');
  {其实不用代码, 在设计时设置一下也可以}
  {也可以用 Image1.Picture.Bitmap.LoadFromResourceName() 从资源文件调入}
end;

end.


方法 2: 用 TBitmap
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  bit: TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bit := TBitmap.Create;
  bit.LoadFromFile('c:\temp\test.bmp');
//  bit.LoadFromResourceName(); //或者从这个命令从资源文件调入
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bit.Free;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.StretchDraw(ClientRect, bit);
end;

end.

posted on 2008-11-25 21:42  万一  阅读(1799)  评论(1编辑  收藏  举报