5

I have written an application that stores photos, keeping the path to the photos in an database. I have encountered a problem. When I click my button to select the picture I want to display in an TImage object for the user to view before saving, I receive the following exception notification: raised exception class: EInvalidGraphic with message "Unknown picture extension (.jpg)'

I'm using an TopenPicture component to go and fetch the image. the openPicture.filter property is set to accept most of the image formats, (jpg, jpeg, png, gif, bmp), but I cannot load any of these formats into the TImage component.

Here is the code I'm using to load the image:

openPicture.Execute();
filename := openPicture.FileName;

if not(fileName = '') then
begin
  imgFoto.Picture.LoadFromFile(filename);
  imgFoto.Visible := true;
end;
RRUZ
  • 130,998
  • 15
  • 341
  • 467
Japster
  • 961
  • 4
  • 19
  • 38
  • 1
    possible duplicate of [TImage does not seem to support Jpeg in D7 (free edition)?](http://stackoverflow.com/questions/3536481/timage-does-not-seem-to-support-jpeg-in-d7-free-edition) – NGLN Apr 17 '12 at 12:07

1 Answers1

11

Add JPEG to the uses clause in the interface section.

This automatically registers .jpg as valid image file extension and couples it to the TJPEGImage class which TPicture will instantiate.

NGLN
  • 41,230
  • 8
  • 102
  • 186
  • 3
    Likewise add pngimage and gifimage or whatever they are called – David Heffernan Apr 17 '12 at 11:10
  • For .png I have this problem: [Fatal Error] UWizard.pas(15): File not found: 'PngImage.dcu' – Slappy Jul 28 '15 at 07:45
  • @Slap Like David says: "or whatever they are called"; your Delphi version uses another filename! – NGLN Aug 09 '15 at 11:50
  • No, I have to download .png sources (.pas files) and add them to my project and build it (Delphi 7) – Slappy Aug 09 '15 at 15:35
  • @Slap Delphi 7 has no build-in PNG support; you must add it yourself. That's why David mentions that the sourcename could differ. Search for or buy a PNG component suite. – NGLN Aug 09 '15 at 16:20