Timage3中的Timage1和Timage2

ml.*_*ml. 0 delphi image

您好可以在Timage3中插入Timage1和Timage2.如果我的Timage1是100x100而我的Timage2 100x100那么它们将在200x100内并排在Timage3中是否可以这样做?

谢谢

And*_*and 7

基本上,你问的是你是否可以创建一个位图bm3,它由两个给定的位图bm1和bm2并排组成.这很容易,但确切的实现取决于您的具体情况.但原则上,你可以做到

bm3 := TBitmap.Create;
bm3.SetSize(200, 100);
BitBlt(bm3.Canvas.Handle, 0, 0, 100, 100, bm1.Canvas.Handle, 0, 0, SRCCOPY);
BitBlt(bm3.Canvas.Handle, 100, 0, 100, 100, bm2.Canvas.Handle, 0, 0, SRCCOPY);
Run Code Online (Sandbox Code Playgroud)

如果bm1和bm2都是100×100 sq.px.TBitmap对象.

或者,如果您更喜欢使用VCL而不是Windows GDI,则可以将两个BitBlt行替换为

bm3.Canvas.Draw(0, 0, bm1);
bm3.Canvas.Draw(100, 0, bm2);
Run Code Online (Sandbox Code Playgroud)

一个完整的例子:

var
  bm1, bm2, bm3: TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Load bm1 and bm2
  bm1 := TBitmap.Create;
  bm1.LoadFromFile('C:\Users\Andreas Rejbrand\Desktop\red.bmp');
  bm2 := TBitmap.Create;
  bm2.LoadFromFile('C:\Users\Andreas Rejbrand\Desktop\blue.bmp');

  bm3 := TBitmap.Create;
  bm3.SetSize(200, 100);
  bm3.Canvas.Draw(0, 0, bm1);
  bm3.Canvas.Draw(100, 0, bm2);

end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0, 0, bm3);
end;
Run Code Online (Sandbox Code Playgroud)

在TImage组件的情况下

假设您的表单上有三个TImage控件,Image1,Image2和Image3,并且两个首先在其中包含图片.那你可以做

procedure TForm1.FormClick(Sender: TObject);
var
  tmp: TBitmap;
begin

  tmp := TBitmap.Create;
  try
    tmp.SetSize(Image1.Picture.Width + Image2.Picture.Width, max(Image1.Picture.Height, Image2.Picture.Height));
    tmp.Canvas.Draw(0, 0, bm1);
    tmp.Canvas.Draw(Image1.Picture.Width, 0, bm2);
    Image3.Picture.Assign(tmp);
  finally
    tmp.Free;
  end;

end;
Run Code Online (Sandbox Code Playgroud)

让Image3并排显示Image1和Image2的图片.