ImageGear for C and C++ on Windows v19.3 - Updated
IG_image_channels_separate
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Image Channel Functions > IG_image_channels_separate

This function separates channels in an image by creating a new image for each channel.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_image_channels_separate(
        HIGEAR hIGear,
        LPAT_CHANNEL_REF channels,
        AT_UINT channelsQty
);

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of image in which to store separated channels.
channels LPAT_CHANNEL_REF Array of channel descriptors for channels to separate.
channelsQty AT_UINT Number of channels to separate.

Return Value:

Returns the number of ImageGear errors that occurred during this function call. If there are no errors, the return value is IGE_SUCCESS.

Supported Raster Image Formats:

All pixel formats supported by ImageGear for C and C++.

Sample:

None

Example:

 
Copy Code
/* Load an image and save all of its channels as 
   separate pages in a multi-page TIFF file */
AT_ERRCOUNT nErrcount;  /* Number of errors on stack */
HIGEAR hImage;          /* Handle of source image */
AT_CHANNEL_REF *chan;   /* Channels to combine */
AT_INT nChannels;       /* Number of channels in image */
AT_INT i;
nErrcount = IG_load_file("test.jpg", &hImage);
nErrcount = IG_image_channel_count_get(hImage, &nChannels);
chan = (AT_CHANNEL_REF *) malloc(nChannels * sizeof(AT_CHANNEL_REF));
for (i = 0; i < nChannels; i++)
{
    chan[i].hImage = hImage;
    chan[i].uNumber = i;
}
nErrcount = IG_image_channels_separate(hImage, chan, nChannels);
for (i = 0; i < nChannels; i++)
{
    nErrcount = IG_fltr_save_file(chan[i].hImage, "test.tif",
        IG_SAVE_TIF_UNCOMP, i, !i);
    IG_image_delete(chan[i].hImage);
}
IG_image_delete(hImage);
free(chan);

Remarks:

Each new image contains one channel with creates a new image for each channels array of pages, where each page contains one channel with color space set to grayscale. This function does not do any color space or pixel conversions.