ImageEn, unit imageenproc




function AutoCrop(Tolerance: Integer; Background: TRGB; DoCrop: Boolean = True): TRect;
function AutoCrop(Tolerance: Integer; Background: TColor; DoCrop: Boolean = True): TRect;


Remove any bordering area of an image of a certain color.

Parameter Description
Tolerance How closely we match the color to Background (0 to 255, where 0 matches only the specified color, and 255 would remove everything)
Background The border color to remove
DoCrop If False the image is not cropped, but the suggested area for cropping is returned as the result

Returns the area to crop or cropped.


// Remove the black border from a scanned document
ImageEnView1.Proc.AutoCrop(10, CreateRGB(0, 0, 0) );

// Crop an image, but not too tightly (leave a 10px margin)
rect := ImageEnView1.Proc.AutoCrop( 0, clWhite, False );
ImageEnView1.Proc.Crop( max( rect.Left - Crop_Margin, 0 ),
                        max( rect.Top - Crop_Margin, 0 ),
                        min( rect.Right + Crop_Margin, ImageEnView1.IEBitmap.Width ),
                        min( rect.Bottom + Crop_Margin, ImageEnView1.IEBitmap.Height ) );

See Also

Public Method  AutoCrop2
Public Method  CropTransparentBorder
Public Method  Crop