ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 CropSelectionEx?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

901 Posts

Posted - Mar 06 2024 :  18:07:42  Show Profile  Reply
Is there a built-in ImageEn method to achieve the "CropSelectionEx" feature?

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."

xequte

38418 Posts

Posted - Mar 06 2024 :  19:00:52  Show Profile  Reply
Hi Peter

There is not a feature available for that, I'm afraid.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

901 Posts

Posted - Mar 07 2024 :  09:50:50  Show Profile  Reply
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.
Go to Top of Page

xequte

38418 Posts

Posted - Mar 07 2024 :  19:46:23  Show Profile  Reply
Hi Peter

Nice one. In what context do you use it?



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

901 Posts

Posted - Mar 08 2024 :  00:45:51  Show Profile  Reply
The conventional clipboard cut operation often results in a noticeable 'scar.'

In contrast, the CropSelectionEx method I've developed leaves no visible traces:

Go to Top of Page

xequte

38418 Posts

Posted - Mar 08 2024 :  02:46:22  Show Profile  Reply
Yes, that is a cool feature.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: