unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs;
type
TForm1 = class(TForm)
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
PiclWidth=96; PiclHeight=96;
PicsWidth=100 ; PicsHeight=20;
procedure GetImageListPic(Bmp,sBmp,lBmp : TBitmap);
var
x,y,x1,y1:integer;
scal,scal1:Single;
begin
sBmp.Width:=PicsWidth;sBmp.Height:=PicsHeight;
lBmp.Width:=PiclWidth;lBmp.Height:=PiclHeight;
lBmp.Canvas.Pen.Color:= RGB (214,211,206);
lBmp.Canvas.Rectangle(0,0,PiclWidth,PiclHeight);
x:=1; y:=1 ; x1:=0; y1:=0;
if Bmp.Width>Bmp.Height then
begin
scal:=(PiclWidth-2)/Bmp.Width;
y:=1+((PiclHeight-2)-Round(bmp.Height*scal)) div 2;
end else
begin
scal:=(PiclHeight-2)/Bmp.Height;
x:=1+( (PiclWidth-2) - Round(bmp.Width*scal) ) div 2;
end;
StretchBlt(lbmp.Canvas.Handle,x,y,Round(bmp.width*scal),Round(bmp.Height*scal),
Bmp.Canvas.Handle,0,0,Bmp.Width,Bmp.Height,SRCCOPY);
if Bmp.Width/Bmp.Height>=PicsWidth/PicsHeight then
begin
scal1:=PicsWidth/Bmp.Width;
y1:=((PicsHeight)-Round(bmp.Height*scal1)) div 2;
end else
begin
scal1:=PicsHeight/Bmp.Height;
x1:=( (PicsWidth) - Round(bmp.Width*scal1) ) div 2;
end;
StretchBlt(sbmp.Canvas.Handle,x1,y1,Round(bmp.width*scal1),Round(bmp.Height*scal1),
Bmp.Canvas.Handle,0,0,Bmp.Width,Bmp.Height,SRCCOPY);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
bmp,sbmp,lbmp : tbitmap;
begin
if OpenPictureDialog1.Execute then
begin
bmp:=tbitmap.Create;
bmp.LoadFromFile(openpicturedialog1.FileName);
sbmp:=tbitmap.Create;
lbmp:=tbitmap.create;
sbmp.Width:= PicsWidth ;
sbmp.Height:= PicsHeight ;
lbmp.Width:=PiclWidth ;
lbmp.Height:=PiclHeight ;
lbmp:=tbitmap.Create;
GetImageListPic(Bmp,sBmp,lBmp);
canvas.Draw(0,0,bmp);
canvas.Draw(400,400,sbmp);
canvas.Draw(500,500,lbmp);
bmp.Free;
sbmp.Free;
lbmp.free;
end;
end;
end.