ImageGear for C and C++ on Windows v20.5 - Updated
IG_IP_crop
API Reference Guide > Core Component API Reference > Core Component Functions Reference > Image Processing Functions > IG_IP_crop

This function crops the image to the specified rectangle.

Declaration:

 
Copy Code
AT_ERRCOUNT ACCUAPI IG_IP_crop(
   HIGEAR hIGear,
   LPAT_RECT lpCropRect
);

Arguments:

Name Type Description
hIGear HIGEAR HIGEAR handle of image.
lpCropRect LPAT_RECT Pointer to an AT_RECT struct specifying the rectangular portion of the image to keep. The remainder of the image is removed and discarded.

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:

Artext, Image Processing, Timing, GUI, MFC PDFDemo

Example:

 
Copy Code
HIGEAR hIGear;            // HIGEAR handle of the image
AT_ERRCOUNT nErrcount;    // Count of errs on stack upon ret from func
AT_DIMENSION nWidth, nHeight;  // Dimensions of the image
AT_RECT rcRect;        // Crop rectangle

// Load image file "picture.bmp" from working directory
nErrcount = IG_load_file("picture.bmp", &hIGear);
if(nErrcount == 0)
{
    // Get dimensions of the image and initialize the crop rectangle
    IG_image_dimensions_get(hIGear, &nWidth, &nHeight, NULL);
    rcRect.left = 0;
    rcRect.top = 0;
    rcRect.right = nWidth / 2;
    rcRect.bottom = nHeight / 2;

    nErrcount = IG_IP_crop(hIGear, &rcRect);
    // ...
    // Destroy the image
    IG_image_delete(hIGear);
}

Remarks:

Only pixels that fall on or inside the lpCropRect rectangle will be kept in the resulting image. The dimensions of the resulting image are then same as that of the lpCropRect. The removed parts of the image are discarded.

If right or bottom bound of the rectangle falls beyond the image dimensions, the rectangle is clipped to the image bounds. The resulting image dimensions cannot be larger than the dimensions of the source image. Use IG_IP_resize_canvas to extend the image bounds without scaling the image.

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