Reputation: 6051
This code:
uses
Vcl.Imaging.jpeg...
...
ThisPicture := TPicture.Create;
try
ThisPicture.LoadFromFile('MyImage.JPE'); // error
...
finally
ThisPicture.Free;
end;
generates this error:
EInvalidGraphic: Unknown picture file extension <.jpe>
ALTHOUGH Vcl.Imaging.jpeg is used. JPG and JPEG can be loaded without problems.
Wikipedia explains that .jpg, .jpeg, .jpe .jif, .jfif, .jfi are extensions of the JPEG format.
So how can I use LoadFromFile('MyImage.JPE') without error?
Upvotes: 3
Views: 6015
Reputation: 612794
The JPE extension is not registered by the Delphi JPEG code. Hence the error. Since you know the image type you can load it directly into a TJPEGImage object:
Image := TJPEGImage.Create;
Image.LoadFromFile(...);
And the assign to the picture control.
ThisPicture.Assign(Image);
Or the simpler solution of registering the JPE extension so that TPicture
associates it with TJPEGImage
. This can be done using TPicture.RegisterFileFormat
:
uses
Vcl.Imaging.JConsts, Vcl.Imaging.jpeg;
....
TPicture.RegisterFileFormat('jpe', sJPEGImageFile, TJPEGImage);
TPicture.RegisterFileFormat('jif', sJPEGImageFile, TJPEGImage);
TPicture.RegisterFileFormat('jfif', sJPEGImageFile, TJPEGImage);
TPicture.RegisterFileFormat('jfi', sJPEGImageFile, TJPEGImage);
For what it is worth, the documentation of RegisterFileFormat
contains this rather quaint line:
The AExtension parameter specifies the three-character system file extension to associate with the graphic class (for example, "bmp" is associated with TBitmap).
Don't worry about the suggestion that extensions have to be exactly three characters in length. That is simply a documentation error.
Upvotes: 6