24 Votes

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

Question by Chematik | 2012-09-13 at 11:28

In my program, I want to load a jpg image dynamically and then it should be displayed. For this, I have drawn a TImage Delphi component on the form and use the following code:

image1.picture.loadfromfile('pic.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
Avatar
18Best Answer24 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.
2012-09-15 at 18:41

ReplyPositive Negative
Avatar
311 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
Avatar
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
Avatar
00 Votes

Thanks for your answer, this working on my code. Hope it is working for other people.
2020-11-26 at 14:03

Positive Negative
Reply
Avatar
26 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
Avatar
06 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

Positive Negative
Avatar
44 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
Reply

Related Topics

WhatsApp: No more Image

Question | 1 Answer

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.