Check uploaded image

Asked

Viewed 815 times

1

There is the possibility to check when an image was loaded into a TImage?

For example: I have a label that appears "Loading Image..." when the TImage load any image, this label should disappear. It is possible?

1 answer

1


Yes. Assuming the image you will upload is from the internet, you can do so:

Var
 imageURL: string;
 MS: TMemoryStream;
 Jpg: TJPEGImage;
begin
 imageURL := 'URL da imagem aqui';
 try
   MS := TMemoryStream.Create;
   IdHTTP1.Get(imageURL, MS);
   if ms.Size > 0 then begin
     Jpg := TJPEGImage.Create;
     MS.Position := 0;
     try
       Jpg.LoadFromStream(MS);
       Image1.Picture.Assign(Jpg);
     finally
       Jpg.Free;
     end;
   end;
 finally
   MS.Free;
 end;

At the event OnProgress() of the component TImage do so:

procedure TForm1.Image1Progress(Sender: TObject; Stage: TProgressStage;
  PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
begin
if PercentDone = 100 then
   Label1.Caption := 'imagem carregada!';
end;
  • 2

    If you are going to upload from the internet the moment you start rendering the image, the label disappears. At least it is missing here. Take a look

  • Verdade @Filipe.Fonseca, before opening the image it goes even... ?

  • @user7605 the image is a JPEG?

  • Perfect @Sunstreaker, thanks!

  • 2

    @user7605 Just remember not to use BMP images, as these do not make use of the Image1progress routine.

  • Okay, thank you @Filipe.Fonseca

Show 1 more comment

Browser other questions tagged

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