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
 Interactive Crop nightmare
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Sep 17 2016 :  09:14:50  Show Profile  Reply
Hello,

I am trying very hard to get Interactive Cropping to work properly.

But I don't understand as to why it is not working as expected.

It seems I am making some grave mistake. But I am not able to catch my mistake.

What I am trying to do is allow user to select a layer and then open a form and allow the user to crop that layer's image in the form interactively.

In the other form the image is coming very small and crop is getting set wrong and if we zoom the image using mouse wheel the crop that is set programmatically seems to dance around....

Here is the code sample along with a sample file saved using SaveAll of IEVect.

https://www.dropbox.com/s/h8g9miunq0dgl3e/InteractiveCropSample.zip?dl=0

Can someone please check this and point out my mistakes.

TIA


Yogi Yang

rmklever

Norway
51 Posts

Posted - Sep 17 2016 :  10:31:59  Show Profile  Reply
Hi,

Try not using layers in the interactive form and it will work a lot better. I got it working by doing some small changes to your source code.

Have a look at this and compare it with yours:

procedure TForm1.Button2Click(Sender: TObject);
var
  CropForm: TfrmCropPhoto;
  CropX, CropY, CropW, CropH: Integer;
  CRect: TRect;
  TotalLayers, CurrLayer: Integer;
begin
  if ImageEnVect1.IsEmpty then
    Exit;

  if ImageEnVect1.CurrentLayer.IsMask then
    Exit;

  CurrLayer := ImageEnVect1.LayersCurrent;

  CropX := 1400;
	CropY := 2390;
	CropW := 878;
	CropH := 800;

  CRect := Rect(CropX, CropY, CropW, CropH);

  CropForm := TfrmCropPhoto.Create(Application);

  CropForm.ienViewCrop.IEBitmap.Assign(ImageEnVect1.CurrentLayer.Bitmap);
  CropForm.ienViewCrop.Proc.ClearAllUndo;
  CropForm.ienViewCrop.Proc.ClearAllRedo;
  CropForm.ienViewCrop.Proc.UndoLimit := 20;

  CropForm.ienViewCrop.CropToolInteraction.SetBitmapPolygon(Rect(0, 0, CropForm.ienViewCrop.IEBitmap.Width, CropForm.ienViewCrop.IEBitmap.Height));

  CropForm.ienViewCrop.CropToolInteraction.DrawGuides := False;
  CropForm.ienViewCrop.CropToolInteraction.AntialiasMode := ierBicubic;
  CropForm.ienViewCrop.CropToolInteraction.GripSize := 12;

  CropForm.ienViewCrop.CropToolInteraction.Mode := iectmRECTANGLE;

  CropForm.ienViewCrop.MouseInteract := [miCropTool];
  CropForm.ienViewCrop.Cursor := crIECrossSight;

  CropForm.ienViewCrop.Fit();

  if CropForm.ShowModal = mrOk then
  begin
    CropForm.ienViewCrop.CropToolInteraction.Crop;
    ImageEnVect1.CurrentLayer.Bitmap.Assign(CropForm.ienViewCrop.IEBitmap);
  end; // if CropForm.ShowModal = mrOk then

  CropForm.Free;
  ImageEnVect1.Refresh;
end;


Some code is needed to make the layer fit the new size (cropped image)...

Roy M Klever
Klever on Delphi - www.rmklever.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Sep 19 2016 :  02:34:13  Show Profile  Reply
Hello Roy,

Thanks for your code sample.

It works but actually I am not able to get the crop part to locate itself accurately to the location that I want.

I have just build this sample to show the problem. But the actual code does much more. For example if there is a mask layer above currently selected layer that the crop should be set to the size of mask in the crop form.

While in your code setting the crop to the whole image is do able but what I want to implement is something like above.

TIA


Yogi Yang
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: