Loading a Picture from a File

From RAD Studio
Jump to: navigation, search

Go Up to Loading and Saving Graphics Files


Your application should provide the ability to load a picture from a file if your application needs to modify the picture or if you want to store the picture outside the application so a person or another application can modify the picture.

To load a graphics file into an image control, call the LoadFromFile method of the image control's Picture object.

The following code gets a file name from an open picture file dialog box, and then loads that file into an image control named Image:

procedure TForm1.Open1Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute then
  begin
    CurrentFile := OpenPictureDialog1.FileName;
    Image.Picture.LoadFromFile(CurrentFile);
  end;
end;
void __fastcall TForm1::Open1Click(TObject *Sender) {
    if (OpenPictureDialog1->Execute()) {
        CurrentFile = OpenPictureDialog1->FileName;
        Image->Picture->LoadFromFile(CurrentFile);
    }
}

See Also