This function loads an image from a file into memory and creates a HIGEAR handle for the image.
Copy Code
|
|
---|---|
AT_ERRCOUNT ACCUAPI IG_load_FD( AT_INT fd, LONG lOffset, UINT nPage, UINT nTile, LPHIGEAR lphIGear ); |
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 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. |
lphIGear | LPHIGEAR | Pointer to HIGEAR object to which this function will return the HIGEAR handle of the image loaded. |
All pixel formats supported by ImageGear for C and C++.
Copy Code
|
|
---|---|
HIGEAR hIGear = 0; /* handle ret'd by IG_load_FD */ HANDLE fd; /* File Descriptor */ LONG lOffset; /* offset to image in file */ UINT nPageNum; /* will be 0 for this call */ AT_ERRCOUNT nErrcount; /* to test for errors */ fd = CreateFile(_T("picture.bmp"), GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(fd != INVALID_HANDLE_VALUE) { nPageNum = 1; /* not a multi-page file */ lOffset = 0; /* access file from start */ /* Load image, and obtain its HIGEAR handle: */ nErrcount = IG_load_FD((AT_INT)fd, lOffset, nPageNum, 0, &hIGear ); CloseHandle(fd); } //... // Destroy the image if(IG_image_is_valid(hIGear)) { IG_image_delete(hIGear); } |
Unlike IG_load_file, this function is used when the file is already open and you have its File handle (fd). The HIGEAR handle, which ImageGear assigns for the loaded image, is returned to you via argument lphIGear. The file indicated by fd may be in any format recognized by ImageGear. IG_load_FD() will determine the format by inspecting the file's header section. See ImageGear Supported File Formats Reference.
Simply loading the file does not cause it to be displayed. Refer to IG_dspl_image_draw and related routines for information about how to display an image once it is in memory. See also IG_load_file_display.
lOffset represents the number of bytes, positive or negative, from the position in the file currently pointed to by fd. The fd may have been moved around a few times so that it is no longer pointing to the beginning of the file. Be sure to keep this in mind as you set the value of lOffset.
The nPage argument is set to 1 or greater if you are loading from a multi-page file to indicate which page (image) you want to load. Set nPage to 1 for a non-multi-page file.
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.
If you wish to make a subsequent call to IG_info_get_FD_ex, you must first move the file pointer (of loaded image) to the beginning of the file, or you will receive an error. This happens because after an image is loaded, the file pointer is positioned at the end of the image in the file. To avoid the error: