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
 Merging all selected Line Layers with Background
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

859 Posts

Posted - Sep 20 2020 :  08:01:49  Show Profile  Reply
In Delphi 10.4.1, I need to merge all selected Line Layers with the Background Image (Layer 0). So I've come up with this code:

procedure TForm1.btnMergeAllSelectedLineLayersWithBackgroundImageClick(Sender: TObject);
var
  selLayers: array of Integer;
  i: Integer;
begin
  Screen.Cursor := crHourGlass;
  try
    for i := 1 to ImageEnView1.LayersCount - 1 do
    begin
      if ImageEnView1.Layers[i].Selected and (ImageEnView1.Layers[i].Kind = ielkLine) then
      begin
        SetLength(selLayers, Length(selLayers) + 1); 
        selLayers[Length(selLayers) - 1] := i;
      end;
    end;

    if Length(selLayers) > 0 then
    begin
      for i := High(selLayers) downto 0 do      
        ImageEnView1.LayersMerge([0, selLayers[i]]);      
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;


It works. But isn't there a more simple BUILT-IN method to do this?

xequte

38176 Posts

Posted - Sep 20 2020 :  16:25:18  Show Profile  Reply
Hi Peter

One of LayersMerge overloads accepts an array of integer, so your second section of code needs only be:

ImageEnView1.LayersMerge( selLayers );

https://www.imageen.com/help/TImageEnView.LayersMerge.html


Alternatively, you can just deselect any non-line layers, and then merge all selected with:

LayersMerge();


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

859 Posts

Posted - Sep 20 2020 :  17:43:15  Show Profile  Reply
Hi Nigel,

I don't need to merge the line-layers among them.

As I wrote, I need to merge all selected Line Layers with the Background Image (Layer 0).
Go to Top of Page

xequte

38176 Posts

Posted - Sep 20 2020 :  23:38:30  Show Profile  Reply
Hi Peter

Is that not the same as:

var
  selLayers: array of Integer;
  i: Integer;
begin
  Screen.Cursor := crHourGlass;
  try
    for i := 0 to ImageEnView1.LayersCount - 1 do
      if ( i = 0 ) or ( ImageEnView1.Layers[i].Selected and (ImageEnView1.Layers[i].Kind = ielkLine)) then
      begin
        SetLength(selLayers, Length(selLayers) + 1); 
        selLayers[Length(selLayers) - 1] := i;
      end;

    ImageEnView1.LayersMerge( selLayers ); 
  finally
    Screen.Cursor := crDefault;
  end;
end;



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

859 Posts

Posted - Sep 21 2020 :  04:37:41  Show Profile  Reply
Hi Nigel,

I am sorry, but:
ImageEnView1.LayersMerge( selLayers );
in this case does in fact only merge the selected line-layers among each other and not with the background image:



As the documentation about LayerList says: "...all layers will be merged into the layer specified by the first index". And since the first index of the LayerList integer-array in this case is the index of the first selected line-layer, the layers from the integer-array are being combined among each other and not with the background image.

And even if you start the loop from 0 as in your code example, it will not work because the condition
(imgMain.Layers[i].Kind = ielkLine)
does not apply to Layer 0 (the background image).

And even if you explicitly add the background-layer in the integer-list loop with:
( i = 0 ) or ( ImageEnView1.Layers[i].Selected and (ImageEnView1.Layers[i].Kind = ielkLine))
it will just combine the background-layer with itself if there are no line-layers selected.

Go to Top of Page

PeterPanino

859 Posts

Posted - Sep 21 2020 :  05:38:42  Show Profile  Reply
BTW, ImageEn is a wonderful Graphics library for Delphi with many powerful possibilities! I like it!
Go to Top of Page

xequte

38176 Posts

Posted - Sep 21 2020 :  16:19:44  Show Profile  Reply
Hi Peter

The code works fine when I test it here.

I've added an error message if there are no line layers selected.

procedure Tfmain.Button14Click(Sender: TObject);
var
  selLayers: array of Integer;
  i: Integer;
begin
  Screen.Cursor := crHourGlass;
  try
    for i := 0 to ImageEnView1.LayersCount - 1 do
      if ( i = 0 ) or ( ImageEnView1.Layers[i].Selected and (ImageEnView1.Layers[i].Kind = ielkLine)) then
      begin
        SetLength(selLayers, Length(selLayers) + 1);
        selLayers[Length(selLayers) - 1] := i;
      end;

    if Length(selLayers) = 1 then
      ShowMessage( 'You have not selected any line layers' )
    else
      ImageEnView1.LayersMerge( selLayers );
  finally
    Screen.Cursor := crDefault;
  end;
end;


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