图片的合并与缩放 - 回复 "錢亞兵" 的问题

问题来源: http://www.cnblogs.com/del/archive/2008/12/30/1316584.html#1417644


unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    Button2: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



{将两个图片横向合并}

procedure TForm1.Button1Click(Sender: TObject);

var

  bit, bit1, bit2: TBitmap;

  h: Integer;

begin

  bit := TBitmap.Create;

  bit1 := TBitmap.Create;

  bit2 := TBitmap.Create;



  bit1.LoadFromFile('c:\temp\test1.bmp');

  bit2.LoadFromFile('c:\temp\test2.bmp');



  h := bit1.Height; if bit2.Height > h then h := bit2.Height;

  bit.SetSize(bit1.Width + bit2.Width, h);



  bit.Canvas.Draw(0, 0, bit1);

  bit.Canvas.Draw(bit1.Width, 0, bit2);



  bit.SaveToFile('c:\temp\test.bmp');



  bit.Free;

  bit1.Free;

  bit2.Free;

end;



{将图片缩小至 1/4}

procedure TForm1.Button2Click(Sender: TObject);

const

  r = 0.25;

var

  bit1, bit2: TBitmap;

begin

  bit1 := TBitmap.Create;

  bit2 := TBitmap.Create;



  bit1.LoadFromFile('c:\temp\test.bmp');



  bit2.SetSize(Trunc(bit1.Width * r), Trunc(bit1.Height * r));

  bit2.Canvas.StretchDraw(Rect(0,0,bit2.Width,bit2.Height), bit1);



  bit2.SaveToFile('c:\temp\test.bmp');



  bit1.Free;

  bit2.Free;

end;



end.


 
   

你可能感兴趣的:(图片)