unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
procedure LoadAndDrawImage(AFile: string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.LoadAndDrawImage(AFile: string);
var
Bmp: TBitmap;
begin
if not FileExists(AFile) then Exit;
Bmp := TBitmap.Create;
try
Bmp.LoadFromFile(AFile);
Canvas.Draw(0, 0, Bmp);
finally
Bmp.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
LoadAndDrawImage(OpenDialog1.FileName);
end;
end.