ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Increase the size of a layer by keeping its AR?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Sep 25 2020 : 06:21:34
I need to programmatically increase the size of a layer by keeping its aspect ratio.

A naive approach would be to increase both the layer-width and the layer-height by one pixel, but that obviously doesn't keep the aspect-ratio when width <> height.

So I came up with this code, assuming that setting TImageEnView.LayersResizeAspectRatio = iearAlways would work even programmatically (it works when resizing the layer with the mouse):

procedure TForm1.btnIncLayerSizeClick(Sender: TObject);
var
  OldLayersResizeAspectRatio: TIELayersResizeAspectRatio;
begin
  OldLayersResizeAspectRatio := ImageEnView1.LayersResizeAspectRatio;
  try
    ImageEnView1.LayersResizeAspectRatio := iearAlways;
    ImageEnView1.Layers[idx].Width := ImageEnView1.Layers[idx].Width + 1;
    ImageEnView1.Update;
    CodeSite.Send('new layer height', ImageEnView1.Layers[idx].Height);
  finally
    ImageEnView1.LayersResizeAspectRatio := OldLayersResizeAspectRatio;
  end;
end;


But unfortunately this does not work programmatically (only when resizing withe mouse).

So is there a method to programmatically increase the size of a layer by keeping its aspect ratio?
5   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Sep 28 2020 : 16:44:01
Hi Peter

I will publish those properties for 9.2.1.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 28 2020 : 05:40:27
Thank you for the hint about using the double versions. Until now I have used the Integer versions obtained by div operation. It worked well but the double type is certainly better.
xequte Posted - Sep 27 2020 : 21:28:06
Note: If you are going to update the values often you should use the double versions to avoid rounding errors:

// Set width to 600 while maintaining AR
ar := ImageEnView1.Layers[idx].Width / ImageEnView1.Layers[idx].Height;
ImageEnView1.Layers[idx].WidthD  := 600;
ImageEnView1.Layers[idx].HeightD := 600 / ar;
ImageEnView1.Update();

// Set height to 600 while maintaining AR
ar := ImageEnView1.Layers[idx].Width / ImageEnView1.Layers[idx].Height;
ImageEnView1.Layers[idx].WidthD  := 600 * ar;
ImageEnView1.Layers[idx].HeightD := 600;
ImageEnView1.Update();


Nigel
Xequte Software
www.imageen.com
xequte Posted - Sep 27 2020 : 21:24:38
Hi Peter

I think at this stage, I will keep AR adjustment a user action feature.

Programmatically, to maintain AR you need only ensure that you update width/height in the ratio of Layer.Height/Layer.Width which is not too taxing, e.g.

// Set width to 600 while maintaining AR
ar := ImageEnView1.Layers[idx].Width / ImageEnView1.Layers[idx].Height
ImageEnView1.Layers[idx].Width  := 600;
ImageEnView1.Layers[idx].Height := Round( 600 / ar );
ImageEnView1.Update();

// Set height to 600 while maintaining AR
ar := ImageEnView1.Layers[idx].Width / ImageEnView1.Layers[idx].Height
ImageEnView1.Layers[idx].Width  := Round( 600 * ar );
ImageEnView1.Layers[idx].Height := 600;
ImageEnView1.Update();


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Sep 25 2020 : 08:58:26
A (TImageEnView) property to help in programmatically resizing a layer with keeping aspect-ratio could be declared as:

TIELayersResizeAROptions = Set of (lrarShapeSize,
                                   lrarBorderWidth,
                                   lrarFontSize);


So when
LayersResizeAROptions = [lrarShapeSize, lrarBorderWidth]
then when changing the shape-size will automatically change the border-width by keeping aspect-ratio and vice-versa.

Or when
LayersResizeAROptions = [lrarShapeSize, lrarBorderWidth, lrarFontSize]
then when changing the text-layer's font-size will automatically change the layer's shape-size and its border-width by keeping aspect-ratio, and vice-versa.

That of course implicates that when lrarShapeSize is included in LayersResizeAROptions then when changing just the shape-WIDTH, it will automatically change shape-HEIGHT by keeping the aspect ratio!

An alternative would be declaring TIELayersResizeAROptions as:

TIELayersResizeAROptions = Set of (lrarShapeWidth,
                                   lrarShapeHeight,
                                   lrarBorderWidth,
                                   lrarFontSize);


The Default value of LayersResizeAROptions would be:
[lrarShapeWidth, lrarShapeHeight]
which would fit the current behavior of aspect-ratio layer-resizing.

What do you think?