写程序中,我们往往需要打开图片,或者打开其他文件,以下是一个最 简单的打开文件操作;
源文件下载地址:http://download.csdn.net/detail/cq20110310/6857603
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.