ImageEn, unit imageenview




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;


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".

- 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.


// 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

// Merge all selected layers

// 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.Layers[1].Transparency := 128; // the second layer has 50% transparency
ImageEnView.LayersMerge(0, 1); // from now we have only one layer

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

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

// Merge all selected line layers with the background image
  selLayers: array of Integer;
  i: Integer;
  for i := 0 to ImageEnView1.LayersCount - 1 do
    if ( i = 0 ) or ( ImageEnView1.Layers[i].Selected and (ImageEnView1.Layers[i].Kind = ielkLine)) then
      SetLength(selLayers, Length(selLayers) + 1);
      selLayers[Length(selLayers) - 1] := i;

  if Length(selLayers) = 1 then
    ShowMessage( 'You have not selected any line layers' )
    ImageEnView1.LayersMerge( selLayers );

See Also

- LayersMergeAll
- LayersMergeFilter
- LayersMergeTo
- IELayersMerge
- LayersSaveMergedTo