Mirror

Preload images (Views: 100)


Problem/Question/Abstract:

I have a form with a TPageControl and a number of pages. On some pages, there is a TImage showing a JPEG picture. I want these images to be loaded when the form is created, not when they are going to be drawn. The problem is that it takes a long time to change page in the page control, if the new page hasn't been shown before.

Answer:

Try something like this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  if Image1.Picture.Graphic is TJPEGImage then
  begin
    TJPEGImage(Image1.Picture.Graphic).DIBNeeded;
  end;
end;

It tells the JPEG to decode the image right away and not on demand as it otherwise would.

<< Back to main page