如何把几张相同大小的图片拼合在 TImage 中 - 回复 "jxjjljf" 的问题

本文提供了一个使用Delphi实现的图片拼接示例代码,通过调整参数可以轻松地改变图片排列方式。该示例展示了如何加载多个图片文件、调整Image1组件的大小以及在画布上绘制这些图片。

问题来源: http://www.cnblogs.com/del/archive/2009/01/09/1373051.html#1743248

procedure TForm1.Button1Click(Sender: TObject);
var
  Bits: array[0..5] of TBitmap; { 假定有 6 张相同大小的图片需要拼合 }
  i,n,x,y: Integer;             { n 用作列数; x,y 用作位置}
begin
  n := 3; { 假如每行排 3 张; 可随意修改}

  { 读取图片, 假如图片是放在 C:\Temp\ 下, 并命名为 1.bmg、2.bmp ... 6.bmp  }
  ChDir('C:\Temp\');
  for i := 0 to Length(Bits) - 1 do
  begin
    Bits[i] := TBitmap.Create;
    Bits[i].LoadFromFile(IntToStr(i+1) + '.bmp');
  end;

  { 设置 Image1 的大小}
  if (n > Length(Bits)) or (n <= 0) then n := Length(Bits);
  Image1.Width := Bits[Low(Bits)].Width * n;
  Image1.Height := Bits[Low(Bits)].Height * (Length(Bits) div n);
  if Length(Bits) mod n > 0 then
    Image1.Height := Image1.Height + Bits[Low(Bits)].Height;

  { 绘制 }
  x := 0;
  y := 0;
  for i := 0 to Length(Bits) - 1 do
  begin
    Image1.Canvas.Draw(x, y, Bits[i]);
    Inc(x, Bits[i].Width);
    if x >= Image1.Width then
    begin
      x := 0;
      Inc(y, Bits[i].Height);
    end;
    Bits[i].Free;
  end;
end;

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/320222

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值