Delphi初浅入门笔记之十:多媒体编程三,打开图片篇

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ExtCtrls, ExtDlgs, jpeg;

type

TForm1 = class(TForm)

OpenPictureDialog1: TOpenPictureDialog;

Image1: TImage;

Button1: TButton;

procedure Button1Click(Sender: TObject);

procedure FormResize(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

openfilepath:string;

begin

openpicturedialog1.Filter:= '全部 (*.jpg;*.jpeg;*.bmp;*.ico;*.emf;*.wmf;*.png)|*.jpg;*.jpeg;*.bmp;*.i' +

'co;*.emf;*.wmf;*.png|JPEG 图像文件 (*.jpg)|*.jpg|JPEG 图像文件 (*.jpeg)|*.jpeg' +

'|位图 (*.bmp)|*.bmp|图标 (*.ico)|*.ico|增强图元文件 (*.emf)|*.emf|图元文件 (*.' +

'wmf)|*.wmf|可移植图片(*.png)|*.png';

if openpicturedialog1.Execute then

begin

openfilepath:=openpictureDialog1.FileName;

image1.Picture.LoadFromFile(openfilepath);

image1.AutoSize:=false;

image1.Stretch:=true;

end;

end;

procedure TForm1.FormResize(Sender: TObject);

begin

//Image1.Width:=form1.ClientWidth+10;

//Image1.Height:=form1.ClientHeight+10;

end;

end.

源代码