Hi Nigel,
In the meantime, I have implemented it:
procedure TformPreview.CropSelectionEx(AImageView: TImageEnView);
// 1. If the selection spans the entire width of the image, the height of the image is reduced by the height of the selection.
// The area above the selection is then merged with the area below the selection to form a single image.
// 2. If the selection spans the entire height of the image, the width of the image is reduced by the width of the selection.
// The area to the left of the selection is then merged with the area to the right of the selection to form a single image.
var
SelectionRect: TIERectangle;
ImageWidth, ImageHeight: Integer;
SelectedRect: TRect;
OutsideTop, OutsideBottom, OutsideLeft, OutsideRight: TIEBitmap;
begin
// Get the dimensions of the image:
ImageWidth := AImageView.IEBitmap.Width;
ImageHeight := AImageView.IEBitmap.Height;
// Get the selection rectangle:
SelectionRect := AImageView.SelectedRect;
// Convert the TIERectangle to TRect:
SelectedRect := IERectangleToRect(SelectionRect);
// Check if the selection spans the entire width of the image:
if SelectionRect.Width = ImageWidth then
begin
// Extract the areas outside of the selection vertically:
OutsideTop := TIEBitmap.Create;
OutsideBottom := TIEBitmap.Create;
try
OutsideTop.Assign(AImageView.IEBitmap);
OutsideBottom.Assign(AImageView.IEBitmap);
// Resize the top part to remove the bottom area:
OutsideTop.Resize(ImageWidth, ImageHeight - SelectedRect.Height - (ImageHeight - SelectedRect.Bottom),
0, 255, iehLeft, ievTop);
// Resize the bottom part to remove the top area:
OutsideBottom.Resize(ImageWidth, ImageHeight - SelectedRect.Bottom, 0, 255, iehLeft, ievBottom);
// Join the bottom part with the top part:
AImageView.Proc.JoinBitmaps(OutsideTop, OutsideBottom, True);
AImageView.Deselect;
finally
OutsideTop.Free;
OutsideBottom.Free;
end;
end
// Check if the selection spans the entire height of the image:
else if SelectionRect.Height = ImageHeight then
begin
// Extract the areas outside of the selection horizontally
OutsideLeft := TIEBitmap.Create;
OutsideRight := TIEBitmap.Create;
try
OutsideLeft.Assign(AImageView.IEBitmap);
OutsideRight.Assign(AImageView.IEBitmap);
// Resize the left part to remove the right area:
OutsideLeft.Resize(ImageWidth - SelectedRect.Width - (ImageWidth - SelectedRect.Right), ImageHeight,
0, 255, iehLeft, ievTop);
// Resize the right part to remove the left area:
OutsideRight.Resize(ImageWidth - SelectedRect.Right, ImageHeight, 0, 255, iehRight, ievTop);
// Join the left part with the right part:
AImageView.Proc.JoinBitmaps(OutsideLeft, OutsideRight, False);
AImageView.Deselect;
finally
OutsideLeft.Free;
OutsideRight.Free;
end;
end;
// Refresh the view to reflect the changes
AImageView.Update;
end;
I can donate it to ImageEn.