ImageGear for C and C++ on Linux v19.10 - Updated
IG_load_mem
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Load Functions > IG_load_mem

This function loads an image from memory and creates HIGEAR handle for the image.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_load_mem(
   LPVOID lpImage,
   AT_UINT nSize,
   UINT nPage,
   UINT nTile,
   LPHIGEAR lphIGear
);

Arguments:

Name Type Description
lpImage LPVOID Pointer to memory location of an image file that is currently in memory.
nSize AT_UINT Size of image in memory.
nPage UINT Page number to load if this is a multi-page 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. Set to 1 for a non-tiled image.
lphIGear LPHIGEAR Pointer to HIGEAR object in which to return ImageGear handle of the newly loaded image.

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

Example:

 
Copy Code
HIGEAR hIGear = 0;      /* handle ret'd by ImageGear  */
char* lpWhereFile; /* ptr to image file in mem   */
AT_UINT nWholeSize;    /* Size of image in memory */
AT_ERRCOUNT nErrcount;  /* to test for errors         */

// Open a file and get its size
FILE* fd = NULL;
fopen_s(&fd, "picture.bmp", "rb");
if(fd != NULL)
{
    fseek(fd, 0, SEEK_END);
    nWholeSize = (AT_UINT)ftell(fd);
    fseek(fd, 0, SEEK_SET);
    // Allocate memory and read the image into the memory buffer
    lpWhereFile = (char*)malloc(nWholeSize);
    fread(lpWhereFile, 1, nWholeSize, fd);
    // File is no longer needed - close it
    fclose(fd);
    // Load image from the memory
    nErrcount = IG_load_mem(lpWhereFile, nWholeSize, 1, 0, &hIGear);
    // delete memory 
    free(lpWhereFile);
}

//...

// Destroy the image
if(IG_image_is_valid(hIGear))
{
    IG_image_delete(hIGear);
}

Remarks:

The entire image file (even if a multi-page file) including header, is in memory. The format must be one of the file formats recognized by ImageGear. See ImageGear Supported File Formats Reference.

Argument lpImage is a pointer to the start of the image file in memory. dwSize is the size of the entire file (even if a multi-page file). For a multi-page file, nPage is the page number to load. Note that page numbers in multi-page files begin at 1, not 0. Set nPage = 1 if the file is a non-multi-page file.

This function creates a DIB for the image and loads the image into it. The handle which ImageGear assigns for this image is returned to you via argument lphIGear.

Note that simply loading the file does not cause it to be displayed. Refer to function IG_dspl_image_draw for how to display an image once it is in memory.

If you set nPage to < 1, ImageGear will default the value to 1; if you set nPage to greater than the number of pages in the document, ImageGear will default the value to the last page number. This same default procedure applies to the nTile parameter as well.

This function is very similar in operation to IG_load_file, except that the file to load from is located in memory rather than on a mass storage device.