![](https://i-blog.csdnimg.cn/blog_migrate/e20fff26d1a4761e07ecbd89e8249f02.png)
UNIT Unit17;
INTERFACE
USES
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ExtDlgs, Vcl.ExtCtrls, Vcl.Imaging.jpeg; //注意:要加入jpej 否侧浏览图片时识别不到
TYPE
TForm17 = CLASS(TForm)
img1: TImage;
dlgOpenPic1: TOpenPictureDialog;
lbl1: TLabel;
edt1: TEdit;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
END;
VAR
Form17: TForm17;
pName: STRING;
IMPLEMENTATION
{$R *.dfm}
procedure TForm17.btn1Click(Sender: TObject);
begin
if (dlgOpenPic1.Execute) then
begin
pName := dlgOpenPic1.FileName;
edt1.Text := pName;
img1.Picture.LoadFromFile(pName) //image的picture属性里的方法加载图片,还有loadFromStream,可以从流加加载。
end;
end;
procedure TForm17.btn2Click(Sender: TObject);
begin
close;
end;
END.