D
D
DeeUs2021-05-24 23:11:23
Delphi
DeeUs, 2021-05-24 23:11:23

Why is an image not inserted from a file into an Image?

Hello!
OpenPictureDialog and Image are located on the form
. OpenPictureDialog added the Images (*.png;*.jpg;*.jpeg;*.bmp) filter and specified it in the FilterIndex
Why is the image from the file not inserted into the Image? (MB it is inserted, but it is not visible on the form. How can I check this by the way?)

button code Open file

procedure TForm1.N14Click(Sender: TObject);
begin
  if OpenPictureDialog1.Execute and FileExists(OpenPictureDialog1.FileName) then
  begin
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
    //memo2.Lines.Add(OpenPictureDialog1.FileName); // проверил имя файла - корректное
    ScrollBox1.HorzScrollBar.Range:=Image1.Picture.Width;
    ScrollBox1.VertScrollBar.Range:=Image1.Picture.Height;
    Image1.Width:=Image1.Picture.Width;
    Image1.Height:= Image1.Picture.Height;
    EsPaintBox1.Width:=Image1.Picture.Width;
    EsPaintBox1.Height:= Image1.Picture.Height;
    ShowWindow(Application.Handle, SW_NORMAL);
    Application.ShowMainForm := true;
    Form1.AlphaBlend := false;
    Form1.AlphaBlendValue := 255;
    TrayIcon1.Visible := true;
    SpeedButton10.Enabled:=true;
    SpeedButton11.Enabled:=true;
    SpeedButton7.Enabled:=true;
    SpeedButton17.Enabled:=true;
    SpeedButton18.Enabled:=true;
    Form1.Visible := True;// Делаем видимой форму приложения
    Form1.WindowState := wsMaximized;//wsNormal; // Разворачиваем
  end;
end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2021-05-24
@DeeUs

1. OpenPictureDialog1 has an option - the file must exist, so you can remove the second condition
2. The code is working, see what's wrong with the picture, or with where and how you place Image1
In the designer, try to select the desired picture and see how it all works is displayed. And do not forget to specify the Vcl.Imaging.jpeg module in uses, otherwise the jpeg may not be loaded (the same with png - Vcl.Imaging.pngimage)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question