How to display all picture formats in TImage using Delphi
Asked Answered
S

1

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;
Shouldst answered 17/4, 2012 at 11:2 Comment(1)
possible duplicate of TImage does not seem to support Jpeg in D7 (free edition)?Astomatous
A
12

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.

Astomatous answered 17/4, 2012 at 11:8 Comment(5)
Likewise add pngimage and gifimage or whatever they are calledScurlock
For .png I have this problem: [Fatal Error] UWizard.pas(15): File not found: 'PngImage.dcu'Bender
@Slap Like David says: "or whatever they are called"; your Delphi version uses another filename!Astomatous
No, I have to download .png sources (.pas files) and add them to my project and build it (Delphi 7)Bender
@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.Astomatous

© 2022 - 2024 — McMap. All rights reserved.