bmp缩略图

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值