ImgInvert(_CurrentImage);

X1:=ImgFindBlackBorderLeft(_CurrentImage, 99.0, 1);

Y1:=ImgFindBlackBorderTop(_CurrentImage, 99.0, 1);

X2:=ImgFindBlackBorderRight(_CurrentImage, 99.0, 1);

Y2:=ImgFindBlackBorderBottom(_CurrentImage, 99.0, 1);

ImgInvert(_CurrentImage);

ContentWidth:=(X2-X1)+1;

ContentHeight:=(Y2-Y1)+1;

CanvasWidth:=ImgGetWidth(_CurrentImage);

CanvasHeight:=ImgGetHeight(_CurrentImage);

XOffset:= ((CanvasWidth- ContentWidth) div 2)-X1;

YOffset:= ((CanvasHeight- ContentHeight) div 2)-Y1;

ImgShift(_CurrentImage,XOffset,YOffset);

ImgCleanBorder( _CurrentImage, 0, 0, CanvasWidth+XOffset-1, CanvasHeight+YOffset-1);


