分享

如何把几张相同大小的图片拼合在 TImage 中

 独孤求财 2012-03-28

问题来源: 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;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多