Search code examples
delphijpegdelphi-7

TImage does not seem to support Jpeg in D7 (free edition)?


procedure TmainForm.FormCreate(Sender: TObject);
  var img : TImage;
      pic:TPicture;

begin
  pic := TPicture.create();
  pic.LoadFromFile('my_picture.jpg');
  img :=  Timage.create(Self);
  img.Picture := pic;
end;

...

"Project MyProect.exe raised exception class EInvalidGraphic 
with message 'Unknown picture extension (.jpg)'" 

and, sure enough, right there in function TPicturePropertyEditor.Execute() it only handles .ICO and .BMP files!

The weird thing is that if I place a TImage on a form at design time & click its Picture property then the file load dialog shows me .JPG files (and crashes if I load one) - _NOTE_ this is the "free for personal use" version of D7 that was given away with a computer mag many years ago.

What to do? Code my own VCL component? Or maybe someone already invented that (FOSS) wheel?


Solution

  • Create a new project, and write (for example)

    procedure TForm1.FormCreate(Sender: TObject);
    var
      img: TPicture;
    begin
      img := TPicture.Create;
      img.LoadFromFile('C:\Users\Andreas Rejbrand\...\tiles55.jpg');
    end;
    

    This will generate the "Unknown picture file extension (.jpg)" error. However, if you add "Jpeg" to the uses clause, then it will work.