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

This function loads an image from a file using user-defined callback functions.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_load_FD_CB_ex(
   AT_INT fd,
   LONG lOffset,
   UINT nPage,
   UINT nTile,
   LPFNIG_RASTER_SET lpfnRasterSet,
   LPFNIG_DIB_CREATE_EX lpfnDIBCreateEx,
   LPVOID lpPrivateData
);

Arguments:

Name Type Description
fd AT_INT Handle of the open file containing the image to be loaded. This handle can be obtained from Microsoft Windows functions such as CreateFile(), and cast to AT_INT for passing to the function parameter. FILE pointers returned by functions such as fopen(), and file handles returned by functions such as _sopen_s() are not supported.
lOffset LONG Offset into the file, in bytes, to where the image begins. This is the offset to the beginning of the header, not to the beginning of the bitmap. lOffset is usually 0.
nPage UINT Page number to load if this is a multi-page (multi-image) file. Note that page numbers begin at 1, not 0. Set nPage to 1 if this is not a multi-page file.
nTile UINT If loading an image that is tiled, you can set the number of a specific tile to load. Tile numbers begin at 1, not 0. Set to 1 for a non-tiled image.
lpfnRasterSet LPFNIG_RASTER_SET Pointer to callback function to be called after each raster line is read.
lpfnDIBCreateEx LPFNIG_DIB_CREATE_EX Pointer to callback function to be called after the file header has been read.
lpPrivateData LPVOID Pointer to a private data area. This pointer will be passed to the callback functions.

Return Value:

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

Supported Raster Image Formats:

All pixel formats supported by ImageGear for C and C++.

Actual set of pixel formats supported by this function can be narrower, depending on the implementation of the user-defined callback functions.

Sample:

Load Callback

Example:

 
Copy Code
AT_ERRCOUNT ACCUAPI MyDIBCreateEx( 
    LPVOID             lpPrivate, /* Private data passed in  */
    const HIGDIBINFO   hDIB       /* DIB info object for DIB */
    )
{
    /* Get info about image and allocate storage here */
    return 0;
}
AT_ERRCOUNT ACCUAPI MyRasterSet( 
    LPVOID           lpPrivate,   /* Private data passed in  */
    const LPAT_PIXEL lpRaster,    /* Raster line to set      */
    AT_PIXPOS        row,         /* Y position in the image */
    DWORD            rasterSize   /* Size of the raster line */
    )
{
    /* Do something with incoming raster data here */
    return 0;
}

void Example_IG_load_FD_CB_ex()
{
    AT_ERRCOUNT nErrcount;  /* Number of errors on stack */
    HANDLE fd;               /* File descriptor */
    DWORD dwPrivate[10];    /* Some private data */ 
    fd = CreateFile(_T("picture.bmp"), GENERIC_READ,
            0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (fd != INVALID_HANDLE_VALUE)
    {
        nErrcount = IG_load_FD_CB_ex(
            (AT_INT)fd,       /* File descriptor             */
            0L,               /* Offset to image             */
            1,                /* Page number to load         */
            1,                /* Reserved. Always set to 1   */
            MyRasterSet,      /* Called for each raster line */
            MyDIBCreateEx,    /* Called after header is read */
            dwPrivate);       /* Callback data               */
        CloseHandle(fd);
    }
}

Remarks:

It is the responsibility of your two callback functions, lpfnDIBCreateEx and lpfnRasterSet, to create the image storage you want. Your lpfnDIBCreateEx callback function is called after the file's header has been read. Then your lpfnRasterSet callback function is called for each raster line read. See the descriptions under function types LPFNIG_DIB_CREATE_EX and LPFNIG_RASTER_SET for how these callback functions are called.

If you want a HIGEAR handle for the DIB your callback functions have created, you can obtain one (after the load is complete) by calling function IG_image_DIB_import.

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