ImageGear for C and C++ on Windows v21.0 - Updated
API Reference Guide / Core Component API Reference / Core Component Functions Reference / DIB Functions / IG_DIB_pix_set
In This Topic
    IG_DIB_pix_set
    In This Topic

    This function sets a pixel at the specified location in the image.

    Declaration:

     
    Copy Code
    AT_ERRCOUNT ACCUAPI IG_DIB_pix_set(
            HIGEAR hIGear, 
            AT_PIXPOS xpos, 
            AT_PIXPOS ypos, 
            const HIGPIXEL hPixel 
    );
    

    Arguments:

    Name Type Description
    hIGear HIGEAR HIGEAR handle of image into which to set pixel.
    xpos AT_PIXPOS X coordinate (0 to width-1).
    ypos AT_PIXPOS Y coordinate (0 to height-1).
    hPixel const HIGPIXEL Pixel data to write.

    Remarks:

    The pixel data is contained by a pixel object with handle of type HIGPIXEL. This pixel object stores values for each channel in the image.

    Supported Raster Image Formats:

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

    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.

    Example:

     
    Copy Code
    AT_ERRCOUNT nErrcount;  /* Number of errors on stack */
    HIGEAR hImage;          /* Handle of image */
    HIGPIXEL hPix;          /* Handle of pixel */
    AT_DIMENSION w, h;      /* Width and height of image */
    AT_INT nChannels;       /* Number of channels in image */
    AT_DIMENSION x, y;      /* Used to loop over image */
    AT_INT c;               /* Used to loop over channels */
    AT_INT nDepth;          /* Channel depth */
    AT_UINT inverted;       /* Inverted channel value */
    /* Invert colors in upper-left quadrant of image */
    nErrcount = IG_load_file("test.jpg", &hImage);
    nErrcount = IG_image_channel_count_get(hImage, &nChannels);
    nErrcount = IG_image_dimensions_get(hImage, &w, &h, NULL);
    for (y = 0; y < h / 2; y++)
        for (x = 0; x < w / 2; x++)
        {
            nErrcount = IG_DIB_pix_get(hImage, x, y, &hPix);
            for (c = 0; c < nChannels; c++)
            {
                IG_image_channel_depth_get(hImage, c, &nDepth);
                nDepth = (1 << nDepth) - 1;
                inverted = nDepth - IG_pixel_value_get(hPix, c);
                IG_pixel_value_set(hPix, c, inverted);
            }
            nErrcount = IG_DIB_pix_set(hImage, x, y, hPix);
            IG_pixel_delete(hPix);
        }
    nErrcount = IG_save_file(hImage, "test.bmp", 
        IG_SAVE_BMP_UNCOMP);
    IG_image_delete(hImage);
    

    Sample:

    Pixel Access