ImageGear for C and C++ on Linux v19.10 - Updated
Detecting Image Format
User Guide > How to Work with... > Common Operations > Detecting Image Format

You can detect the format of an image file before and after loading it in the HIGEAR handle using functions IG_fltr_detect_...():

All three functions return the type of image format as an IG_FORMAT_ constant, as delineated in the accucnst.h file. See enumIGFormats.

The code fragment below allows you to sort image files by their formats and then choose how to use them:

C and C++ 
Copy Code
AT_ERRCOUNT nErrCount = IGE_SUCCESS;/* will hold returned error count */
AT_MODE nFormatID;
...
nErrCount = IG_fltr_detect_file( "image.tiff", &nFormatID );
if( nFormatID==IG_FORMAT_TIF )
{
...
}

For better performance or for some other purposes, use the special functions IG_fltr_load_file_format() and IG_fltr_pagecount_file_format() if the image format is known. Those functions accept the first parameter as the format ID and do not perform detect operations like IG_fltr_load_file() does, but immediately start to operate with the data, assuming the specified format. If the data is invalid or the image format is different, then an error is placed in the error stack.