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 calculate Ratio properly?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Jan 31 2015 :  07:37:13  Show Profile  Reply
My problem is a bit complicate so let me try and explain it here...

I have implemented a log in which if a user Resizes currently active Layer interactively using Mouse on completion of Resizing process I check if the Layer above current layer is Mask of not and if it is Mask I also resize that layer as per the current location and size. I have programmed this part in OnLayerNofiy event.

But my problem starts here:
If the Mask Layer above current Layer is smaller than current layer (and it X, Y location are different also) then it gets sized to the size of current layer.

Instead of this what I want to achieve is that if the Layer is moved of Resized then the Mask Layer should also get moved or resized appropriately taking into consideration the current location as well as size of Mask Layer compared to Current Layer.

How to achieve this?

Please help.

TIA




Yogi Yang

xequte

39052 Posts

Posted - Feb 02 2015 :  15:07:45  Show Profile  Reply
Hi Yogi

It sounds like you are doing it the right way. In OnLayerNotify you would check for a resize and automatically set the size and position of the associated mask.

In what way does it not work?


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

yogiyang

India
727 Posts

Posted - Feb 04 2015 :  07:34:23  Show Profile  Reply
Hi Nigel,
quote:
In what way does it not work?

It works properly but my problem is a bit more deep than what is looks on the surface.

I have a Layer which had following geometry:
X is 10 px
Y is 7 px
Width is 346 px
Height is 600 px

I have a Mask Layer which has following geometry:
X is 23 px
Y is 10 px
Width is 250 px
Height is 489 px

Now when I code in OnLayerNotify event as follows:

if (event = ielResized) then
begin
LL := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX;
LT := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY;
LW := ImageEnView1.Layers[ImageEnView1.LayersCurrent].Width;
LH := ImageEnView1.Layers[ImageEnView1.LayersCurrent].Height;

if (ImageEnView1.LayersCurrent) < (ImageEnView1.LayersCount - 1) then
begin
	if ImageEnView1.Layers[ImageEnView1.LayersCurrent + 1].IsMask = True then
	begin
	  ImageEnView1.LockUpdate;
	  ImageEnView1.Proc.SaveUndo();
	  ImageEnView1.Layers[ImageEnView1.LayersCurrent + 1].PosX := LL;
	  ImageEnView1.Layers[ImageEnView1.LayersCurrent + 1].PosY := LT;
	  ImageEnView1.Layers[ImageEnView1.LayersCurrent + 1].Width := LW;
	  ImageEnView1.Layers[ImageEnView1.LayersCurrent + 1].Height := LH;
	  ImageEnView1.UnLockUpdate;
	end;
end;


The Mask Layer's X, Y, Width and Height get set to Active Layers X, Y, Width and Height.

So how can I solve this?

One way would be to calculate some kind of ratio but I don't know as to how to do this.

TIA

Yogi Yang




Yogi Yang
Go to Top of Page

xequte

39052 Posts

Posted - Feb 04 2015 :  19:23:44  Show Profile  Reply
Hi Yogi

You will need to ensure that you maintain the original aspect ratio of your mask.

See the GetImageRectWithinArea methods in hyieutils.pas, which should get you going.

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