ImageGear Professional for Linux
Saving to a Disk File Using a File Descriptor Handle

You can use the  IG_save_FD() function to save a HIGEAR image to a file that has already been opened and for which you have a File Descriptor handle (for example, your application may have opened the file using the Windows function _lopen()). IG_save_FD() will permit you to insert an image into a multi-page file (instead of merely appending it, as IG_save_file() would do.)

IG_save_FD() is called with five arguments, of which the HIGEAR image handle and lFormatType have the same meaning as in a call to IG_save_file(). The other parameters are the File Descriptor handle, fd obtained by the Windows function call that opened the file, a reserved argument nReserved, which should always be set to 0, and nPageNum, which allows you to specify the page in which to insert the image. If you want to append image(s) to a file, you can set nPageNum to IG_APPEND_PAGE.

The following example shows IG_save_FD() being used to insert an image as page 3 into an existing a multi-page file:

 
Copy Code
HIGEAR        hIGear;        /* ImageGear handle             */
INT        d;        /* File Descriptor handle    */
UINT        nPageNum,        /* page # to insert image as    */
        nReserved;        /* for future expansion    */
AT_ERRCOUNT nErrcount;                /* # of errors on stack    */
AT_LMODE        lFormatType;        /* type of format to save to            */
/ *Windows call to open file with write privileges                     */
fd = _lopen("picture.tif", WRITE);
nPageNum = 3;            /* save this image as page #        */
nReserved = 0;            * always set to 0 for now        */
lFormatType = IG_SAVE_TIF_JPG; /* format is TIFF-JPEG                    */
/* save the HIGEAR image as page 3 of file whose descriptor is fd:*/
nErrcount = IG_save_FD(hIGear, fd, nPageNum, nReserved,lFormatType,);

If the file "picture.tif" has five pages, the new image will be inserted into the position of the third page, and what was formerly page three will now be page four, and so on. Remember that ImageGear treats the first page of a multi-page file as page 1, not 0. Setting the nPageNum parameter to 0 will append your image(s) to the file. If you set nFormatType to a type that doesn't support multiple pages, then the file will be overwritten with a single image.

Inserting pages to a multi-page file does not physically rearrange the image in the file. Rather, the offset table is adjusted to hold the new address(es) of the inserted page(s), and the new order of the image within the file.

lFormatType should be set to one of the IG_SAVE_ constants, which also include the compression type. Note that TIFF has more than one compression type, and that there are different constants to represent TIFF with each type of compression. If you call IG_save_FD() for a multiple-page file, you must supply the format type (from accucnst.h) for the image to be appended to the file. If you do not know the format of the destination file, first call IG_info_get_FD_ex() and use the format information returned to decide which format to use.

The following pseudo-code example demonstrates how to write a multi-page image using IG_save_FD():

 
Copy Code
lFormat = IG_SAVE_TIF_UNCOMP;
fd = _lopen (szFile,OF_READWRITE);
for (i = 1; i<=nPages; i++)
{
/*Seek to the beginning of the file before writing each page ImageGear will
automatically find the correct file position of the new page */
    seek(fd, 0, SEEK_SET );
    /*Write each next page                 */
    nErrcount = IG_save_FD(hIGear, fd, i, 0, lFormat);
}
close(fd);

When you call OS SEEK or an equivalent function to set the file pointer, the stream needs to be positioned at the FIRST byte of a multi-page image. This is the only way in which a filter can recognize that the image is multi-page.

A file should be opened with both READ and WRITE access.

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback