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
 How to convert an Obj Shp to Selection at the...
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Mar 17 2017 :  07:29:56  Show Profile  Reply
Hello,

I am using ImageEnVect to allow user to draw a rectangle shape and the press a button to create selection of the size of the shape at the same location where the shape is placed but I am not able to get the selection at the same location.

I am using following code:
MyX := ievMain.ObjLeft[SelectedObjID];
    MyY := ievMain.ObjTop[SelectedObjID];
    MyW := ievMain.ObjWidth[SelectedObjID];
    MyH := ievMain.ObjHeight[SelectedObjID];

    ievMain.Select(MyX, MyY, MyW, MyH);

I have tried setting Selection Base to both but still not result.

How to get the functionality as described above?

TIA


Yogi Yang

w2m

USA
1990 Posts

Posted - Mar 17 2017 :  14:14:38  Show Profile  Reply
I can not get it to function well either. I can set the selection, but the coordinates are not correct. I have no idea why. I even tried to convert XY to Bitmap coordinates without success. However, your XY coordinates are incorrect.
MyX := ievMain.ObjLeft[SelectedObjID];
MyY := ievMain.ObjTop[SelectedObjID];
MyW := ievMain.ObjWidth[SelectedObjID];
MyH := ievMain.ObjHeight[SelectedObjID];

ievMain.Select(MyX, MyY, MyX + MyW, MyY + MyH);

I guess I am having a bad day, I should be able to get it to work.
ImageEnVect.LockUpdate and ImageEnVect.UnLockUpdate may be necessary to see the selection. Without that I do not even see a selection.

procedure TForm1.dxBarButton1Click(Sender: TObject);
var
  i: Integer;
  iLeft: integer;
  iTop: integer;
  iX: Integer;
  iY: Integer;
  iX2: Integer;
  iY2: Integer;
  iWidth: Integer;
  iHeight: Integer;
  iHObj: Integer;
begin
  if Assigned(cxPageControl1.ActivePage) then
  begin
    ImageEnVect := TImageEnVect(cxPageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnVect) then
    begin
      ImageEnVect.LockUpdate;
      for i := 0 to ImageEnVect.ObjectsCount - 1 do
      begin
        iHObj := ImageEnVect.GetObjFromIndex(i);
        if ImageEnVect.IsSelObject(iHObj) then
        begin
          iLeft := ImageEnVect.ObjLeft[iHObj];
          iTop := ImageEnVect.ObjTop[iHObj];
          iX := ImageEnVect.XScr2Bmp(iLeft);
          iY := ImageEnVect.YScr2Bmp(iTop);
          iWidth := ImageEnVect.XScr2Bmp(ImageEnVect.ObjWidth[iHObj]);
          iHeight := ImageEnVect.YScr2Bmp(ImageEnVect.ObjHeight[iHObj]);
          iX2 := iX + iWidth;
          iY2 := iY + iHeight;
          ImageEnVect.UnSelObject(iHObj);
          ImageEnVect.Select(iX, iY, iX2, iY2, iespReplace);
          ImageEnVect.UnLockUpdate;
        end;
        Exit;
      end;
    end;
  end;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

yogiyang

India
727 Posts

Posted - Mar 18 2017 :  00:47:29  Show Profile  Reply
Hello Bill,

Thanks for your inputs. I will try them.

Let us see, what Nigel has to say about this issue...

Actually it should work as expected as we are reading the coordinates from a vector object and trying to create a selection using them.

 
ievMain.Select(MyX, MyY, MyX + MyW, MyY + MyH);


I think this is not necessary as I am reading the coordinates from and existing object. But I will give this a try though.

Once again thanks for your inputs and suggestions.

TIA


Yogi Yang
Go to Top of Page

xequte

38615 Posts

Posted - Mar 19 2017 :  04:28:47  Show Profile  Reply
Hi Yogi

Is the selection out by OffsetX x OffsetY?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Mar 19 2017 :  18:32:34  Show Profile  Reply
I managed to get it to function correctly. The problem (incorrect coordinates) was caused because I converted coordinates to Bitmap coordinates and I should have used ClientArea coordinates to set the selection. In my test project the SelectionBase property is iesbClientArea.
procedure TForm1.CreateSelectionFromObject1Click(Sender: TObject);
var
  i: Integer;
  iHObj: Integer;
  iLeft: Integer;
  iTop: Integer;
  iWidth: Integer;
  iHeight: Integer;
  iRight: Integer;
  iBottom: Integer;
begin
  ImageEnVect1.LockUpdate;
  for i := 0 to ImageEnVect1.ObjectsCount - 1 do
  begin
    iHObj := ImageEnVect1.GetObjFromIndex(i);
    if ImageEnVect1.IsSelObject(iHObj) then
    begin
      iLeft := ImageEnVect1.ObjLeft[iHObj];
      iTop := ImageEnVect1.ObjTop[iHObj];
      iWidth := ImageEnVect1.ObjWidth[iHObj];
      iHeight := ImageEnVect1.ObjHeight[iHObj];
      iRight := iLeft + iWidth;
      iBottom := iTop + iHeight;
      ImageEnVect1.UnSelObject(iHObj);
      ImageEnVect1.Select(ImageEnVect1.XBmp2Scr(iLeft), ImageEnVect1.YBmp2Scr(iTop), ImageEnVect1.XBmp2Scr(iRight),
        ImageEnVect1.YBmp2Scr(iBottom), iespReplace);
      ImageEnVect1.UnLockUpdate;
    end;
    Exit;
  end;
end;

After the procedure is executed a selection appears on top of the object. If you move the object you will see both the object and the selection. This code seems to work perfectly even if the image is zoomed.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38615 Posts

Posted - Mar 19 2017 :  23:41:04  Show Profile  Reply
Thanks Bill,


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Mar 28 2017 :  10:26:30  Show Profile  Reply
Hello Bill,

You code works like a charm!

It skipped my mind that we have to convert/calculate objects coordinates using XBmp2Scr.

I was under the impression that Object coordinates can be used directly for selection.

Once again, Thanks.


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