24 Votes

Delphi: Loading JPEG image in TImage does not work: Exception EInvalidGraphic: Unknown picture file extension (.jpg)

Question by Chematik | Last update on 2021-05-17 | Created on 2012-09-13

I would like to dynamically load a JPG image in one of my Delphi programs so that it can be displayed in my program. To do this, I dragged a TImage component from Delphi onto the form and used the following code:

Image1.Picture.LoadFromFile('image.jpg');

Unfortunately, this is not working at all and instead, I get an error with the following error message:

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

In other words, Delphi seems to do not understand JPG graphics. But I think: if not JPEG, what then? How can I correct the error?

ReplyPositiveNegativeDateVotes
22Best Answer30 Votes

Just add "Jpeg" to the USES-list at the top of your code.

You have to do that, because otherwise, Delphi can not understand the JPG-format. With this correction, it should work.

After that, above it should look similiar to that:

uses
  Windows, Messages, ... SysUtils, Jpeg;

And you can load JPG images into your TImage.
Last update on 2021-05-17 | Created on 2012-09-15

ReplyPositive Negative
715 Votes

I will thank you Delphian on behalf of myself and the person who asked it since that person seems to be too lazy lol
2013-08-04 at 00:16

Positive Negative
06 Votes

Thats it. Thanks Delphian.

(Comment to short?? Sorry only wanted to say Thank you Delphian..) Hope this is long enough to say thanks?
2015-07-09 at 13:06

Positive Negative
00 Votes

Thanks for your answer, this is working in my code.

Hope it is working for other people, too.
2020-11-26 at 14:03

Positive Negative
Reply
37 Votes

Hey I'm also stuck in this same situation... I have added Jpeg to uses. But still its giving me the same error.

This is my code:

uses
  Vcl.Imaging.jpeg;

procedure TLoginForm.Button3Click(Sender: TObject);
begin
  imgUserPic.Picture.LoadFromFile('C:\Users\Joel\Desktop\DEVELOPING\Users\Joel.jpeg');
end;

Can someone help me?
2016-03-02 at 22:20

ReplyPositive Negative
55 Votes

You forget this line before the begin.

Var imguserpic : tjpegImage;

That because it give you an error.
2017-05-13 at 18:09

Positive Negative
Reply
17 Votes

Perhaps you can try to add the complete Vcl.Imaging name space to your project.

Go to: Project > Options > Delphi Compiler > Unit Scope Names Menu.
2016-03-03 at 18:34

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.