ImageGear for C and C++ on Windows v19.8 - Updated
IG_save_mem_CB_ex
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Save Functions > IG_save_mem_CB_ex

This function saves the image referenced by hIGear to a memory buffer using user-defined callback functions.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_save_mem_CB_ex(
   LPVOID lpImage,
   AT_UINT nImageSize,
   AT_UINT nBufferSize,
   UINT nPage,
   UINT nReserved,
   AT_LMODE lFormatType,
   LPFNIG_RASTER_GET lpfnRasterGet,
   LPFNIG_DIB_GET_EX lpfnDIBGetEx,
   LPVOID lpPrivateData,
   LPAT_UINT lpActualSize
);

Arguments:

Name Type Description
lpImage LPVOID Memory buffer to which to save the image.
nImageSize AT_UINT Size of the image if it already exists in the buffer, 0 otherwise.
nBufferSize AT_UINT Size of the memory buffer.
nPage UINT If saving to a multi-page file, set this to the page number to insert this page as. Note that page numbers begin at 1, not 0. Otherwise set to 1.
nReserved UINT Reserved, should be set to 0 for now.
lFormatType AT_LMODE Specifies the format to use for saving, and also the compression scheme if applicable. See enumIGSaveFormats.
lpfnRasterGet LPFNIG_RASTER_GET Pointer to a function of type LPFNIG_RASTER_GET, which will be called for each raster line of the image, before that line is saved.
lpfnDIBGetEx LPFNIG_DIB_GET Pointer to a function of type LPFNIG_DIB_GET, which will be called just prior to saving the DIB header.
lpPrivateData LPVOID Pointer to a private data area which is passed to the above two callback functions each time they are called.
lpActualSize LPAT_UINT Actual size of the image is returned in the variable referenced by this pointer. Can be NULL.

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     nErrcount;            // Count of returned errors on stack
HIGEAR hIGear;                        //ImageGear handle
AT_BYTE* lpMemoryBlock;                // Memory block to save the image to
AT_UINT nMaxSize;                    // Size of the memory block

nErrcount = IG_load_file("picture.bmp", &hIGear);
if(nErrcount == 0)
{
    // Get a required size of the memory block
    nErrcount = IG_save_file_size_calc ( hIGear, IG_SAVE_BMP_UNCOMP, &nMaxSize);
    // Allocate a memory block
    lpMemoryBlock = (AT_BYTE*)malloc(nMaxSize);
    // Save image to the memory block in BMP format without compression:
    nErrcount = IG_save_mem_CB_ex(lpMemoryBlock, 0, nMaxSize, 1, 0, IG_SAVE_BMP_UNCOMP, 
        MyRasterGetEx, MyDIBGetEx, &hIGear, NULL); 
    // Destroy the image
    IG_image_delete(hIGear);
    // Some usage of the image in the memory
    //...
    free(lpMemoryBlock);
}

Remarks:

This function works similarly to IG_save_FD_CB_ex, except that the saving is made to a memory buffer rather than a file.

In order for an ImageGear append page operation to work properly, the memory buffer must point to the very beginning of the existing image, rather than to one of its pages, start of pixel data, or any custom wrapper preceding the image.