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
 Copy selection to another TImageEnVect
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jwest

Brazil
67 Posts

Posted - Jul 02 2011 :  19:04:15  Show Profile  Reply
Hi,

I have a TImageEnVect with vectorial objects.
I select a rectangle with a parcel of the image and with some vectorial objects into it.

How could I copy the content of this rectangle(parcel of image and objects) to another TImageEnVect?

Thanks in Advance,

Luiz

w2m

USA
1990 Posts

Posted - Jul 03 2011 :  07:03:27  Show Profile  Reply
Selecting the objects with miSelect works fairly well but is not perfect. You may be able to improve selecting the objects with the selection... Maybe Fabrizio will assist here.

But for now try this:

procedure TMainForm.ImageEnVect1MouseMove( Sender: TObject; Shift: TShiftState; X, Y: Integer );
var
  hobj: Integer;
  Distance: Double;
begin
  if ImageEnVect1.MouseCapture then
  begin
    ASelectionChanging := true;
    // Select object if the object is in the selection
    // This is not perfect but works
    ImageEnVect1.MaxSelectionDistance := ImageEnVect1.SelX2 - ImageEnVect1.SelX1;
    if ImageEnVect1.MaxSelectionDistance < 0 then
      ImageEnVect1.MaxSelectionDistance := ImageEnVect1.SelY2 - ImageEnVect1.SelY1;
    if ImageEnVect1.MouseInteract = [ miSelect ] then
    begin
      hobj := ImageEnVect1.FindObjectAt( X, Y, Distance );
      if ( hobj <> -1 ) and ( Distance < ImageEnVect1.MaxSelectionDistance ) then
      begin
        if not ImageEnVect1.IsSelObject( hobj ) then
          ImageEnVect1.AddSelObject( hobj );
      end;
    end;
  end;
end;

procedure TMainForm.CopySelectedObjects1Click( Sender: TObject );
// copy the selection and selected objects to ImageEnVect2
var
  rc: TRect;
begin
  // copy background selection to ImageEnVect2.IEBitmap
  ImageEnVect1.CopySelectionToIEBitmap( ImageEnVect2.IEBitmap, false );
  // copy selected objects to ImageEnVect2
  ImageEnVect1.CopySelectedObjectsTo( ImageEnVect2 );
  // UnSelAllObjects
  ImageEnVect1.UnSelAllObjects;
  // show the number og objects in ImageEnVect2
  showmessage( IntToStr( ImageEnVect2.ObjectsCount ) );
end;


William Miller
Go to Top of Page

jwest

Brazil
67 Posts

Posted - Jul 03 2011 :  15:14:54  Show Profile  Reply
Hi,

I tried your code but only the image is copied. No vectorial objects appears.

I think I have to loop into objects and convert coordinates, width, height to the new destiny.

Some help will be appreciated.


Regards,

Luiz

Go to Top of Page

w2m

USA
1990 Posts

Posted - Jul 03 2011 :  16:57:56  Show Profile  Reply
The objects are copied here.

When you make the selection with the mouse do the objects have selection handles? After you select and there are no objects with handles then the ImageEnVect1.CopySelectedObjectsTo( ImageEnVect2 ) will not work.

How are you selecting the objects? With Mouseinteract = miselect?

I used the vectorial demo to test this. Try it with that first before your app. You should not have to do anything more to get the objecys to appear.

William Miller
Go to Top of Page

jwest

Brazil
67 Posts

Posted - Jul 04 2011 :  06:43:37  Show Profile  Reply
With this code, all is working.
Thanks for your help.

  procedure SelObjsInRect(im:TImageEnVect;aobj: integer; xx1, yy1, xx2, yy2: integer);
  var
    o: integer;
    ax1, ay1, ax2, ay2: integer;
    rc:TRect;
    Kind:TIEVObjectKind;
  begin
    if aobj = -3 then
    begin
      for o := 0 to  im.ObjectsCount - 1 do
        SelObjsInRect(im, im.GetObjFromIndex(o) , xx1, yy1, xx2, yy2) 
    end
    else
    begin
        im.GetObjRect(aobj,rc);
        ax1 := rc.left;
        ay1 := rc.top;
        ax2 := rc.Right;
        ay2 := rc.Bottom;
        Kind:=im.ObjKind[aobj];
        if (Kind = iekLINE) or (Kind = iekRULER) or (Kind = iekPOLYLINE) or (Kind = iekANGLE) or (Kind = iekLINELABEL) then
          OrdCor(ax1, ay1, ax2, ay2);
        if (ax1 >= xx1) and (ax2 <= xx2) and (ay1 >= yy1) and (ay2 <= yy2) and (not im.IsSelObject(aobj)) then
          im.AddSelObject(aobj);
    end;
  end;

prcodeure copy_objects_and_image_from_rect;
begin
        Item:= TImageEnVect.create(self);
        ........
        if ( ImageEnVect1.Selected )then begin
          ImageEnVect1.CopySelectionToIEBitmap(Item.IEBitmap);
          SelObjsInRect(ImageEnVect1,-3,
           ImageEnVect1.SelX1, ImageEnVect1.SelY1,
           ImageEnVect1.SelX2, ImageEnVect1.SelY2);
          for i:=0 to ImageEnVect1.SelObjectsCount - 1 do begin
            hobj:=ImageEnVect1.SelObjects[i];
            ImageEnVect1.GetObjRect(hobj,rc);
            kk:=ImageEnVect1.ObjLeft[hobj];
            ImageEnVect1.CopyObjectTo(hobj ,Item);
            jj:=ImageEnVect1.SelX1;
            Item.ObjLeft[-2]:=kk-jj;
            kk:=ImageEnVect1.ObjTop[hobj];
            jj:=ImageEnVect1.SelY1;
            Item.ObjTop[-2]:=kk-jj;
          end;
          Item.Update;
          ImageEnVect1.UnSelAllObjects;
end
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: