Make image responsive in Delphi

Asked

Viewed 1,350 times

3

I’m in a project and I need to put a background image, I would like to leave this responsive image but I’m not getting it. I’m using the Timage to insert the image.

1 answer

3


There are two ways of doing, in time design or by code, let’s go the first option.

Design Time:

As mentioned by @lucaswmolin, click on the TImage and in the properties will set first of all the image in picture then we will make the component responsive by defining alclient to the property align, then on the option Stretch we define how True to make the image you open the same size as the component. As you can see in the image below: inserir a descrição da imagem aqui

Code:

By code just use the following example in onCreate form:

procedure TForm1.FormCreate(Sender: TObject);
begin
  //vai abrir a imagem 
  Image1.Picture.LoadFromFile('caminho');
  //define o tamanho do componente ao form 
  Image1.Align := AlClient;
  //defini o tamanho da imagem ao componente
  Image1.Stretch := True;
end;

EDIT1:


After the comment of @Murilopecht that in the version Delphi 10.2 was not working I went to test and actually does not work if the project created is a "Multi-device Application" the steps for the image to stay working are as follows:

first Copy a Timage to the form
2nd In properties defines client for the option align.
In properties Multirestbitmap option click on the 3 points and we will load the image path, see in the image below where to load the path: inserir a descrição da imagem aqui

To use the code option, just 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;
  • so buddy, I added Timage but did not find in properties the picture element to be changed.

  • even when I add the Timage element and add it to the form’s oncreate line: Image1.Picture.Loadfromfile('path'); Delphi says that "does not contain a Member named 'Picture''."

  • 1

    @Murilopecht edited the answer with a photo of the location of the property, just click on the 3 points and add the image

  • does not have this property because I am using Delphi 10.2 Tokyo.

  • so I still can’t solve it, because the answer you sent me is for Iphi 2010, and I’m using Iphi 10.2 Tokyo.

  • @Murilopecht I’ll do some research and edit my answer if I can

  • Thank you very much.

  • @Murilopecht what kind of project are you creating? vcl Forms application, multi-device application,.... could you tell me to help you solve your problem?

  • thank you very much, helped me a lot.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.