Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all picture formats in TImage using Delphi

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;
like image 720
Japster Avatar asked Apr 17 '12 11:04

Japster


1 Answers

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.

like image 141
NGLN Avatar answered Oct 28 '22 02:10

NGLN