ImageGear for C and C++ on Windows v20.0 - Updated
IG_fltr_detect_mem
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Filter Functions > IG_fltr_detect_mem

This function detects the format of an image located in the memory.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_fltr_detect_mem(
   LPVOID lpImage,
   AT_UINT nSize,
   LPAT_MODE lpFileType
);

Arguments:

Name Type Description
lpImage LPVOID Pointer to a memory buffer containing the image.
nSize AT_UINT Size of image in memory.
lpFileType LPAT_MODE Pointer to an AT_MODE variable in which the file type will be returned. See enumIGFormats for possible values. If the file format can not be detected, this parameter will return IG_FORMAT_UNKNOWN.

Return Value:

Returns 0 if successful. Otherwise, returns the number of ImageGear errors that occurred during this function call.

Supported Raster Image Formats:

This function does not process image pixels.

Sample:

None

Example:

 
Copy Code
AT_ERRCOUNT nErrCount; // will hold returned error count
AT_MODE nFormatID;
AT_BYTE* lpImage = NULL;

// Read an image into the memory
FILE* fp;
fopen_s(&fp, "picture.tif", "rb");
if(fp != NULL)
{
    long fileSize;
    fseek(fp, 0, SEEK_END);
    fileSize = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    // Allocate memory buffer
    lpImage = (AT_BYTE*)malloc(fileSize);
    if(lpImage != NULL)
    {
        // Read file into the memory
        fread(lpImage, 1, fileSize, fp);
        // Detect file format in the memory
        nErrCount = IG_fltr_detect_mem(lpImage, fileSize, &nFormatID);
        if(nFormatID == IG_FORMAT_TIF)
        {
            // ...
        }
        // Delete memory
        free(lpImage);
    }
    fclose(fp);
}

Remarks:

See also the section Detecting Image File Format.

Is this page helpful?
Yes No
Thanks for your feedback.