打开图片

Delphi图片加载
本文介绍了一个使用Delphi实现的简单程序,该程序包含一个按钮和一个图像组件。点击按钮后,程序将弹出一个对话框让用户选择一张图片,选中的图片随后会在图像组件中显示出来。此示例代码展示了如何利用Delphi内置的组件来完成基本的图片加载功能。

窗体设计如图:

image button OpenPictureDialog 各一个

代码:

 1 unit Unit1;
 2 
 3 interface
 4 
 5 uses
 6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtDlgs, Vcl.StdCtrls, Vcl.ExtCtrls;
 8 
 9 type
10   TForm1 = class(TForm)
11     Image1: TImage;
12     Button1: TButton;
13     OpenPictureDialog1: TOpenPictureDialog;
14     procedure Button1Click(Sender: TObject);
15   private
16     { Private declarations }
17   public
18     { Public declarations }
19   end;
20 
21 var
22   Form1: TForm1;
23 
24 implementation
25 
26 {$R *.dfm}
27 
28 procedure TForm1.Button1Click(Sender: TObject);
29 var
30   openfilepath:string;
31 begin
32   if OpenPictureDialog1.Execute then
33   begin
34     openfilepath := OpenPictureDialog1.FileName;//把打开文件名字赋值给openfilepath
35     Image1.Picture.LoadFromFile(openfilepath);  //在image1打开图片
36   end;
37 
38 end;
39 
40 end.

 

转载于:https://www.cnblogs.com/zty123/p/5983859.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值