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

1

4
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?

Hawsepiece answered 21/8, 2010 at 5:33 Comment(5)
Can't you use the TJpegImage?Monopoly
d'oh !! (+1) why not post that as an answer?Hawsepiece
A good idea ... but .. it is not proving easy as I am trying to make a component and TJpegImage isn't descended from TCOmponentClass, but I am working on it (so maybe don't post it as an answer quite yet, sorry)Hawsepiece
@mawg: Asked 14 hours ago, a very popular language, but only eight views? Do you know why? Because you didn't specify the "Delphi" tag. (Specifying "Delphi-7" alone does not make the question visible at the place where everyone is looking: stackoverflow.com/questions/tagged/delphi)Personable
+1 both actually I considered the Delphi tag & decided (probably wrongly) that it was because I use an "old" and "free" version of Delphi. I would like to hope that Jpeg is supported in Delphi 2010. Guess I guessed wrongly. Thanks.Hawsepiece
P
7

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.

Personable answered 21/8, 2010 at 19:41 Comment(3)
D'oh! bad Borland, I guess. Without the use clause I can even preview my JPG, but when I load it crashes. I thought I was going to have to take their code & extend it (convert Jpeg to BMP on the fly) Thanks for the answer!Hawsepiece
No,not bad Borland (for a change). <g> The IDE was compiled with JPEG support (uses JPEG), so the JPEG stuff works in the IDE. You need to do the same so that JPEGs work in your app by also using JPEG.Donny
...while not including the JPEG unit saves you from unnecessarily increasing your EXE when you never plan to use it anyway.Gynaecology

© 2022 - 2024 — McMap. All rights reserved.