Declaration
function FindFileFormat(const FileName: WideString; FindMethod: TIEFindFormatMethod = ffContentOnly): TIOFileType;
Description
Returns the file format of the specified file by reading the file and trying to recognize the file header.
FindMethod determines how the file extension is used to aid or confirm format detection:
Value | Description |
ffContentOnly | Only the content of the file is examined. The filename is ignored (No extension checking) |
ffVerifyByExtension | The content is examined to determine the type. This is then compared to the file extension and ioUnknown is returned if the type does not match (Strict extension checking) |
ffFallbackToExtension | The content is examined to determine the type. If it cannot be determined (which can happen with some Dicom and Raw formats), then the type is guessed by the file extension (Optimistic extension checking) |
Some formats
cannot be detected by content alone. Sony ARW and Kodak DCR are TIFF internally so will return as ioTIFF. WBMP and Implicit Dicom will return as ioUnknown.
Note:
FindFileFormat uses
FindStreamFormat to detect the image format.
// Determine the file type only by examining the file header/content
if FindFileFormat( sFilename, ffContentOnly ) = ioJPEG then
ShowMessage( 'File content is JPEG' );
// Determine the file type by examining the file header/content, check it has the correct file extension
if FindFileFormat( sFilename, ffVerifyByExtension ) = ioJPEG then
ShowMessage( 'File content is JPEG and it has a JPEG extension' );
// Determine the file type by examining the file header/content. If that fails use the correct file extension
if FindFileFormat( sFilename, ffFallbackToExtension ) = ioDICOM then
ShowMessage( 'File appears to be a DICOM' );
var
ss: TIOFileType;
begin
ss := FindFileFormat('C:\myfile.dat', ffContentOnly);
if ss = ioGIF then
ImageEnView1.IO.LoadFromFileGIF('C:\myfile.dat')
else
if ss = ioJPEG then
ImageEnView1.IO.LoadFromFileJpeg('C:\myfile.dat');
end;