ImageGear for C and C++ on Windows v20.0 - Updated
IG_save_FD
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Save Functions > IG_save_FD

This function saves the image referenced by hIGear to a file that has already been opened, and for which your application has the File descriptor.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_save_FD(
   HIGEAR hIGear,
   AT_INT fd,
   UINT nPage,
   UINT nReserved,
   AT_LMODE lFormatType
);

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of image to save.
fd AT_INT Handle of the open file for saving the image. This handle can be obtained from Microsoft Windows function 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.
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 always be set = 0 for now.
lFormatType AT_LMODE Specifies the format to use for saving, and also the compression scheme if applicable. See enumIGSaveFormats.

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:

Load Callback, Filters, Multimedia

Example:

 
Copy Code
HIGEAR hIGear;            //ImageGear handle
HANDLE fd;                //File Descriptor
AT_ERRCOUNT nErrcount;  //Number of errors on stack

// Load the image
nErrcount = IG_load_file("picture.tif", &hIGear);
if(nErrcount == 0)
{
    // Create a file for writing
    fd = CreateFile(_T("picture_new.tif"), GENERIC_WRITE,
        0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if(fd != INVALID_HANDLE_VALUE)
    {
        // Save the HIGEAR image as page 3 of file whose descriptor is fd:
        nErrcount = IG_save_FD(hIGear, (AT_INT)fd, 1, 0, IG_SAVE_TIF_UNCOMP);
        CloseHandle((HANDLE)fd);
    }
    // Destroy the image
    IG_image_delete(hIGear);
}

Remarks:

When saving to an existing file having a multi-page format, this function permits you to insert your image into the file at the page number you designate by argument nPage. If you want to append your image as the final page of the file, set nPage = IG_APPEND_PAGE. lFormatType should specify the format type and compression of the already existing file. If you do not know the format type you can first make a call to IG_info_get_FD_ex.

See Saving for additional information.

When saving to a non-multi-page format, this function will save a new single-image file of the format type and compression specified by lFormatType. Any previous version of the file will be lost. When saving to a non-multi-page format, set nPage = 1.

In order for an ImageGear append page operation to work properly, the file handle 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.

Appending and Inserting: While IG_APPEND_PAGE assures you that your loaded image will be appended to a pre-existing multi-page file, there are two other instances in which the value you assign to nPage will cause an append: if you set nPage to less than 1, or if you set nPage to greater than the number of pages in the file to which you are saving.

To summarize: ImageGear will insert your image to a pre-existing multi-image file if you set nPage to a value between 1 and the number of the last page in the file.

ImageGear supports the writing of tiled images for specific image formats, but does not support the insertion, replacement, or appending of individual tiles.

Is this page helpful?
Yes No
Thanks for your feedback.