ImageGear for C and C++ on Windows v19.10 - Updated
IG_fltr_save_mem
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Filter Functions > IG_fltr_save_mem

This function stores the image referenced by hIGear to the specified memory buffer.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_fltr_save_mem(
   HIGEAR hIGear,
   LPVOID lpImage,
   AT_UINT nImageSize,
   AT_UINT nBufferSize,
   AT_LMODE lFormatType,
   AT_UINT nPageNumber,
   AT_BOOL bOverwrite,
   LPAT_UINT lpActualSize
);

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of the image to save.
lpImage LPVOID Pointer to first byte of memory area in which to save.
nImageSize AT_UINT Size of image (if exists).
nBufferSize AT_UINT Size of memory block.
lFormatType AT_LMODE Specifies the format to use for saving, and also the compression scheme if applicable. See enumIGSaveFormats for possible values.
nPageNumber AT_UINT Specifies the page number of the page inserted into a multi-page file. Note that page numbers begin at 1, not 0. Set to 0 to append the page after the last page of the source file. Set to 1 if the file format does not support multipage, or if saving to a new file.
bOverwrite AT_BOOL Set to TRUE to overwrite existing file during the saving. Set to FALSE to insert or append the page to the file, if the format supports multipage saving.
lpActualSize LPAT_UINT Size of new or updated file in memory.

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++.

Sample:

Memory IO

Example:

 
Copy Code
AT_ERRCOUNT nErrCount;

HIGEAR hIGear = 0;
AT_UINT nFileSize;    // File size returned;
nErrCount = IG_load_file("picture.tif", &hIGear);
if(nErrCount == 0)
{
    // Get required memory size
    nErrCount = IG_fltr_save_mem_size_calc(hIGear, NULL, 0, IG_SAVE_TIF_UNCOMP, 1, TRUE, &nFileSize);
    if(nErrCount == 0)
    {
        // Allocate memory
        LPAT_BYTE memBuffer = (LPAT_BYTE)malloc(nFileSize);
        nErrCount = IG_fltr_save_mem(hIGear, memBuffer, 0, nFileSize, IG_SAVE_TIF_UNCOMP, 1, TRUE, &nFileSize);

        //...

        free(memBuffer);
    }
    IG_image_delete(hIGear);
}

Remarks:

lFormatType is used to set the format and compression (if applicable) of the output file. If you want to have ImageGear use the file extension provided in your filename string (lpszFilename) to determine the file format in which to save the file, set lFormatType = IG_SAVE_UNKNOWN.

Before using this function, the application must allocate a memory buffer, sufficient for storing the saved image. Use IG_fltr_save_mem_size_calc to determine the necessary buffer size.

This function is similar to the IG_save_mem function, but it allows you to insert a new page in multi-page file as either the end page or the page with a given nPageNumber number.

See also the section Saving.