John
John

Reputation: 35

Join Multiple Images IN FMX?

In VCL this is how i make a single image from two images while creating space between them:

 procedure TForm2.Button1Click(Sender: TObject);
var
p1,p2:string;
b1,b2:TBitmap;
bitmap: TBitmap;
begin
 p1:='C:\Users\John\Desktop\p1.bmp';
 p2:='C:\Users\John\Desktop\p2.bmp';
 b1:=TBitmap.Create;
 b1.LoadFromFile(p1);
 b2:=TBitmap.Create;
 b2.LoadFromFile(p2);
  sBit:= TBitmap.Create;
  try
   sBit.Height:=b1.Height;
   sBit.Width:=b1.Width+5+b2.Width;
   sBit.Canvas.Draw(0,0,b1); //Drawing First Bitamp here
   sBit.Canvas.Draw(b1.Width + 5,0,b2);// Drawing Second one 
   Image1.Picture.Bitmap.Assign(sBit);
  finally
   sBit.FreeImage;
  end;
end; 

Now How Can i draw the same in FMX ?

EDIT

Using Bitmap.CopyFromBitmap Works!!

 procedure process;
 var
  p1,p2: String;
  b1,b2,b3:TBitmaps;
  rect: TRect;
  begin
  //load both bitmaps to b1 and b2.
  rect.Left:=0;
  rect.Top:=0;
  rect.Width:=b1.Width;
  rect.Height:=b1.Height; 
  b3:= TBitmaps.Create;
  b3.Height:= b1.height;
  b3.widht:=b1.width;
  b3.CopyFromBitmap(b1,rect,0,0);
  b3.CopyFromBitmap(b2,rect,b1r.Width+5,0);
  Image1.Bitmap.Assign(b3);
end; 

Upvotes: 1

Views: 720

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595981

In VCL, you can't load a PNG image into a TBitmap, only a BMP image. You would have to use TPngImage instead for b1 and b2. TPngImage can be Draw()'n onto a VCL TCanvas.

FMX's TBitmap supports PNG, though.

In FMX, the equivalent of Canvas.Draw() in this situation would be to use TBitmap.CopyFromBitmap():

Copies a rectangular area from a specified bitmap to the current bitmap.

And then use Image1.Bitmap.Assign(sBit); to assign the final TBitmap to the TImage (there is no TPicture in FMX).

Upvotes: 2

Related Questions