I'm in a project and need to put a background image, I would like to make that image responsive, but I can not. I'm using Timage
to insert the image.
I'm in a project and need to put a background image, I would like to make that image responsive, but I can not. I'm using Timage
to insert the image.
There are two ways to do design time or code , let's go first.
Design Time:
As mentioned by @lucaswmolin, click on component TImage
and on properties you will first define everything in% with% then we will make the component responsive by setting picture
to property alclient
, then in option align
set it to Stretch
to make the image to be opened with the size equal to the component. As you can see in the image below:
Code:
Bycode,justusethefollowingexampleinTrue
ofform:
procedureTForm1.FormCreate(Sender:TObject);begin//vaiabriraimagemImage1.Picture.LoadFromFile('caminho');//defineotamanhodocomponenteaoformImage1.Align:=AlClient;//definiotamanhodaimagemaocomponenteImage1.Stretch:=True;end;
EDIT1:
Afterthecommentfrom@MuriloPechtthatintheDelphiversion10.2wasnotworkingIwenttotestanditdoesnotreallyworkiftheprojectcreatedisa"Multi-Device Application" the steps for the image to work are as follows: / p>
1st Copy a Timage to the form 2nd In properties set onCreate
to the option client
. > 3rd properties option MultiRestBitmap clicks on the 3 points and we will load the path of the image, see the image below where to load the path:
To use the code option, simply use the following:
procedure TForm1.FormCreate(Sender: TObject);
begin
//vai abrir a imagem
Image1.MultiResBitmap[0].bitmap.LoadFromFile('caminho');
//define o tamanho do componente ao form
Image1.Align := TAlignLayout.Client;
end;