hi is it possible to insert Timage1 and Timage2 inside Timage3. if my Timage1 is 100x100 and my Timage2 100x100 then they will be side by side inside 200x100 in Timage3 is it possible to do so?
thank you
hi is it possible to insert Timage1 and Timage2 inside Timage3. if my Timage1 is 100x100 and my Timage2 100x100 then they will be side by side inside 200x100 in Timage3 is it possible to do so?
thank you
Essentially, you are asking if you can create a bitmap bm3 which consists of two given bitmaps, bm1 and bm2, side by side. This is easy, but the exact implementation depends on your specific context. But in principle, you could do
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);
if bm1 and bm2 are both 100×100 sq. px. TBitmap objects.
Alternatively, if you prefer to work with VCL rather than Windows GDI, you can replace the two BitBlt lines with
bm3.Canvas.Draw(0, 0, bm1);
bm3.Canvas.Draw(100, 0, bm2);
A complete example:
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;
Assume that you have three TImage controls on your form, Image1, Image2, and Image3, and that the two first have pictures in them. Then you can do
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;
to let Image3 display the pictures of Image1 and Image2 side by side.