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
 Polygon Selection Rotate
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Dec 05 2011 :  16:30:59  Show Profile  Reply
I would like to rotate an existing polygon selection?

Thanks.

AndyColmes

USA
351 Posts

Posted - Dec 06 2011 :  00:14:07  Show Profile  Reply
Or can I do the following instead:

1. Make a polygon selection
2. Convert the selection to an object
3. Rotate the object
4. Use th object boundaries to copy out the bitmap

How would I do this correctly in code?

Thanks.
Go to Top of Page

fab

1310 Posts

Posted - Dec 06 2011 :  00:45:47  Show Profile  Reply
I suggest to use layers instead of vectorial objects:

// Create a layer from current selection
ImageEnVect1.LayersCreateFromSelection();

// Remove selection
ImageEnVect1.DeSelect();

// Allow user to rotate the new layer
ImageEnVect1.MouseInteract := ImageEnVect1.MouseInteract + [miRotateLayers];

When finished you can merge the new layer with the background image.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 06 2011 :  01:08:44  Show Profile  Reply
I would like to use the polygon selection coordinates to "cut" out the image and copy it to a TIEBitmap. How would I do this with layers?

Thanks Fabrizio.
Go to Top of Page

fab

1310 Posts

Posted - Dec 06 2011 :  01:20:12  Show Profile  Reply
"Cut" must be divided in two operations. The first one is to create the new layer with LayersCreateFromSelection. The next step is to remove (fill?) the selected area. For example you could make it transparent with SetSelectedAreaAlpha(0):

// create layer from selection
ImageEnVect1.LayersCreateFromSelection(); 

// select layer 0 and set selected area of that layer to be transparent
ImageEnVect1.LayersCurrent := 0;
ImageEnVect1.SetSelectedAreaAlpha(0);

// select layer 1 to allow user to move or rotate the area
ImageEnVect1.LayersCurrent := 1;
ImageEnVect1.MouseInteract := ImageEnVect1.MouseInteract + [miRotateLayers];
ImageEnVect1.DeSelect();



Of course you can get points of the selection using PolySelPoints, PolySel and PolySelCount.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 06 2011 :  01:27:23  Show Profile  Reply
I used to be able to convert a selection (rectangle) to an IEKBOX object (for re-displaying purposes) and on a later time in the code, using the object coordinates, I was able to create a selection from the object and "cut" out the image to a new TIEBitmap.

But how would I do this with polygon? I know there is an object type IEKPolyLine, but not sure how to apply it using the method above for rectangles.

Please help. Thanks Fabrizio.
Go to Top of Page

fab

1310 Posts

Posted - Dec 06 2011 :  01:51:50  Show Profile  Reply
You can create a polygon object (iekPolyLine) using CreatePolygonsFromSelection.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 06 2011 :  02:56:10  Show Profile  Reply
Thanks Fabrizio. How do I create a selection from a IEKPolyLine object or "cut" the image to a TIEBitmap from the polygon object?
Go to Top of Page

fab

1310 Posts

Posted - Dec 06 2011 :  03:18:11  Show Profile  Reply
quote:
How do I create a selection from a IEKPolyLine object or "cut" the image to a TIEBitmap from the polygon object?


You should create a selection point by point, reading each point from the polyline and add it to selection.
For example, assuming hobj is your iekPolyLine object:

ImageEnVect1.SelectionBase := iesbBitmap;
ImageEnVect1.LockPaint();
for i:=0 to ImageEnVect1.ObjPolylinePointsCount[hobj]-1 do
    ImageEnVect1.AddSelPoint( ImageEnVect1.ObjPolylinePoints[hobj, i].x, ImageEnVect1.ObjPolylinePoints[hobj, i].y );
ImageEnVect1.EndSelect();
ImageEnVect1.UnLockPaint();



Of course you can cut (fill or make it transparent) the selected area with ImageEnVect1.Proc.Fill or ImageEnVect1. SetSelectedAreaAlpha methods.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 06 2011 :  04:33:58  Show Profile  Reply
Thank you Fabrizio.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 18 2011 :  08:43:19  Show Profile  Reply
I have a problem with my code where the image showing from the coordinates of the selection is wrong.

Basically, I load an annotation file IEV and after loading, I would read the object's info to create a preview. The preview is a cut-out image from the selection created from the object.

Can you help? I have a feeling it has to do with SelectionBase. My current ImageEnVect is using iesbClientArea.

procedure TfrmForm.CreatePreview;
var
x: Integer;
Bmp: TIEBitmap;
begin
if (ImageEnVect1.ObjKind[0] = IEKPolyLine) or (ImageEnVect1.ObjKind[0] = IEKEllipse) then begin
ImageEnVect1.SelectionBase := iesbBitmap;
ImageEnVect1.LockPaint();
for x:=0 to ImageEnVect1.ObjPolylinePointsCount[0]-1 do
ImageEnVect1.AddSelPoint( ImageEnVect1.ObjPolylinePoints[0, x].x, ImageEnVect1.ObjPolylinePoints[0, x].y );
ImageEnVect1.EndSelect();
ImageEnVect1.UnLockPaint();
ImageEnVect1.SelectionBase := iesbClientArea;
end;
if (ImageEnVect1.ObjKind[0] = IEKBOX) then begin
ImageEnVect1.Select( ImageEnVect1.ObjLeft[0], ImageEnVect1.ObjTop[0], (ImageEnVect1.ObjWidth[0]-ImageEnVect1.ObjLeft[0]), (ImageEnVect1.ObjHeight[0]-ImageEnVect1.ObjTop[0]), iespReplace );
end;
ImageEnVect1.Update;

Bmp := TIEBitmap.Create;
try
ImageEnVect1.CopySelectionToIEBitmap( Bmp, True );
ImageEnView1.IEBitmap.Assign( Bmp );
ImageEnView1.Update;

//My preview of the cut-out image
ImageEnView2.IEBitmap.Assign( Bmp );
ImageEnView2.Update;
finally
Bmp.Free;
end;

ImageEnVect1.Deselect;
end;
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 18 2011 :  19:55:23  Show Profile  Reply
In my code, I set my ImageEnVect1 with SelectionBase iesbBitmap and it works for the polyline, but not for the IEKBOX where I do the Select. Where is my problem?

Please help. Thanks.
Go to Top of Page

AndyColmes

USA
351 Posts

Posted - Dec 18 2011 :  21:07:59  Show Profile  Reply
Solved my issue. I made a mistake here:

ImageEnVect1.Select( ImageEnVect1.ObjLeft[0], ImageEnVect1.ObjTop[0], (ImageEnVect1.ObjWidth[0]-ImageEnVect1.ObjLeft[0]), (ImageEnVect1.ObjHeight[0]-ImageEnVect1.ObjTop[0]), iespReplace );

when it should be:

ImageEnVect1.Select( ImageEnVect1.ObjLeft[0], ImageEnVect1.ObjTop[0], (ImageEnVect1.ObjWidth[0]+ImageEnVect1.ObjLeft[0]), (ImageEnVect1.ObjHeight[0]+ImageEnVect1.ObjTop[0]), iespReplace );

Thanks again.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: