ImageEn, unit imageenproc |
|
TImageEnProc.AutoCrop
Declaration
function AutoCrop(Tolerance: Integer; Background: TRGB; DoCrop: Boolean = True): TRect;
function AutoCrop(Tolerance: Integer; Background: TColor; DoCrop: Boolean = True): TRect;
Description
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.
Note: AutoCrop() does
not consider the alpha channel
Demo
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
Examples
// Remove the black border from a scanned document
ImageEnView1.IO.Acquire();
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 ) );
// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );

// Remove any black border from the image (with tolerance of 30)
ImageEnView1.Proc.AutoCrop( 30, clBlack );

See Also