ImageEn, unit imageenview

TImageEnView.LayersMerge

TImageEnView.LayersMerge


Declaration

procedure LayersMerge(IncludeBackground: Boolean = False); overload;
procedure LayersMerge(Layer1, Layer2: integer; RemoveUpperLayer: Boolean = true); overload;
procedure LayersMerge(LayerList: array of integer); overload;
procedure LayersMerge(LayerList: TIEArrayOfInteger); overload;


Description

Merges two or more layers into one layer. The new layer has the lesser index.
The new layer will inherit the Layers.Transparency and the bitmap's alpha channels.
The LayersMerge() overload (without parameters) will merge selected layers. If IncludeBackground = True, the selected layers will be merged with layer 0 (i.e. merged to background).

Parameter Description
Layer1 Index of the first layer to merge
Layer2 Index of the second layer to merge
RemoveUpperLayer If RemoveUpperLayer is false, the upper layer will not be removed
LayerList An array of layer indexes to remove. The array must be ordered and all layers will be merged into the layer specified by the first index. Empty list means "all layers"

Note:
 To merge a layer with its own mask (to create a layer with the transparency of the mask) pass only two indexes (i.e. the indexes of the layer and the mask).
 If any of the layers are not a TIEImageLayer, they will be converted to a TIEImageLayer
 LayersMergeFilter will specify the quality of image layers, if they do not have a custom UseResampleFilter
 When passing an integer array, ensure the numbers are ordered upward, e.g. [3, 5, 9]




Masks and Merging

To merge a layer with its own mask (i.e. to create a layer with the transparency of the mask) pass only two indexes (i.e. the indexes of the layer and the mask).
When merging, all layers - except for masks - are merged into the first layer. If the first layer has a mask it is not merged, it is maintained as a mask for all merge layers.
For example, if you are merging two layers, each with an associated layer mask, the bottom layer, and upper layer with its mask will be merged. The mask of the bottom layer will remain untouched.
If you intend to create a single merged layer without a mask (maintin the overall appearance) then merge the first layer with its mask, before the overall merge.


Example

// Merge layer 1 with background (layer 0)
ImageEnView1.LayersMerge( [0, 1] );

// Merge layers 0, 1 and 2
ImageEnView1.LayersMerge([ 0, 1, 2 ]);

// Merge all layers
ImageEnView1.LayersMerge([]);

// Merge all selected layers
ImageEnView1.LayersMerge();

// Merge all selected layers to background
ImageEnView1.LayersMerge( True );

// Merge layer 1 with its mask
ImageEnView1.LayersMerge( 1, 2 );

// we want to get a background image and then merge over it another image in semi-transparency.
ImageEnView.IO.LoadFromFile('C:\background.jpg');
ImageEnView.LayersAdd();
ImageEnView.IO.LoadFromFile('C:\foreground.jpg');
ImageEnView.Layers[1].Transparency := 128;  // the second layer has 50% transparency
ImageEnView.LayersMerge(0, 1);   // from now we have only one layer
ImageEnView.IO.SaveToFile('C:\output.jpg');

// Merge all layers with tag value of 1
var
  selLayers: array of Integer;
  I: Integer;
begin
  for I := 1 to  ImageEnView1.LayersCount - 1 do
    if ImageEnView1.Layers[I].Tag = 1 then
    begin
      SetLength(selLayers, Length(selLayers) + 1);
      selLayers[Length(selLayers) - 1] := I;
    end;

  if Length(selLayers) > 0 then
    ImageEnView1.LayersMerge( selLayers );
end;

// Merge all selected line layers with the background image
var
  selLayers: array of Integer;
  i: Integer;
begin
  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 );
end;


See Also

 LayersMergeAll
 LayersMergeFilter
 LayersMergeTo
 IELayersMerge
 LayersSaveMergedTo