unit uOpenFile; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ExtDlgs,jpeg; type TForm1 = class(TForm) btnOpenFile: TButton; image: TImage; OpenDialog: TOpenDialog; procedure btnOpenFileClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnOpenFileClick(Sender: TObject); var openPath:string; begin OpenDialog.Title := '打開圖片'; OpenDialog.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 openDialog.Execute then begin openPath:=OpenDialog.FileName; image.Picture.LoadFromFile(openPath); image.AutoSize:=False; image.Stretch:=True; end; end; end.