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
 Merge All Layers With Alpha

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
w2m Posted - Apr 16 2012 : 05:39:15
Is it possible to merge all layers and maintain alpha values after the merge? It appears that ImageENView.LayersMergeAll converts the bitdepth to 24.

I found the answer to my own question, but so that others know you can call LayersMerge and maintain alpha values:

for i := 1 to ImageEnView.LayersCount - 1 do
ImageEnView.LayersMerge ( 0, i );

LayersMerge makes the new layer looking at Layers.Transparency and at the bitmap's alpha channels.

William Miller
4   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Feb 05 2018 : 10:33:11
Nigel,

I uninstalled the ImageEn packages from the IDE and closed the IDE.
I totally deleted all ImageEn files from the components folder.
I extracted the files in the repository zip file to the components folder.
I restarted the IDE and installed the ImageEn packages.

The source was from the repository.

procedure TForm1.AddLayer1Click(Sender: TObject);
var
  iRGB: TRGB;
  iLayer: Integer;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      Screen.Cursor := crHourglass;
      try
        iLayer := ImageEnView.LayersAdd(ielkImage);
        ImageEnView.LayersCurrent := iLayer;
        ImageEnView.Layers[iLayer].Name := 'Layer ' +
          IntToStr(ImageEnView.LayersCount + 1);
        ImageEnView.Layers[iLayer].Selectable := True;
        ImageEnView.Layers[iLayer].PosX := 0;
        ImageEnView.Layers[iLayer].PosY := 0;
        ImageEnView.Layers[iLayer].Width := ImageEnView.IEBitmap.Width;
        ImageEnView.Layers[iLayer].Height := ImageEnView.IEBitmap.Height;
        iRGB := ImageEnView.IEBitmap.Pixels[0, ImageEnView.IEBitmap.Height - 1];
        ImageEnView.Proc.SetTransparentColors(iRGB, iRGB, 0);
        ImageEnView.Update;
        ImageEnView.IEBitmap.Modified := True;
        UpdateGUI;
        UpdateFrame;
        UpdateLayers;
        DrawLayers;
        UpdateStatusBar;
        EnableControls(LayersTabSheet1, True);
      finally
        Screen.Cursor := crDefault;
      end;
    end;
  end;
end;

procedure TForm1.DrawRectangle;
{ Draw rectangle. }
var
  iIECanvas: TIECanvas;
  iPenSize: Integer;
  iPenColor: TColor;
  iPenAlpha: Integer;
  ix1, ix2, iy1, iy2: Integer;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      MyUndo(ImageEnView);
      { Draw on the Non-Alpha Canvas }
      iIECanvas := TIECanvas.Create(ImageEnView.IEBitmap.Canvas,
        Antialias1.Checked, UseGDIPlus1.Checked);
      iPenSize := StrToIntDef(PenSize1.Text, 15);
      iPenColor := PenColor.Color;
      iPenAlpha := IEOpacityToAlpha(StrToIntDef(PenOpacity1.Text, 100));
      iIECanvas.Pen.Color := iPenColor;
      iIECanvas.Pen.Transparency := iPenAlpha;
      iIECanvas.Pen.Style := psSolid;
      iIECanvas.Pen.Width := iPenSize;
      iIECanvas.Brush.Style := bsClear;
      ix1 := AStartX;
      iy1 := AStartY;
      ix2 := ALastX;
      iy2 := ALastY;
      { Adjust the coordinates based on the direction of the drag }
      if ix2 <= ix1 then
      begin
        ix1 := ix1 + iPenSize;
        if ix2 = 1 then
          ix2 := 0;
      end;
      if iy2 <= iy1 then
      begin
        iy1 := iy1 + iPenSize;
        if iy2 = 1 then
          iy2 := 0;
      end;
      { Order the coordinates, putting the first as top-left }
      OrdCor(ix1, iy1, ix2, iy2);
      iIECanvas.Rectangle(ix1, iy1, ix2, iy2);
      iIECanvas.Free();
      { Draw on the Alpha Canvas }
      iIECanvas := ImageEnView.IEBitmap.AlphaChannel.CreateROICanvas
        (Rect(ix1 - iPenSize, iy1 - iPenSize, ix2 + iPenSize, iy2 + iPenSize),
        Antialias1.Checked, UseGDIPlus1.Checked);
      iIECanvas.Pen.Width := iPenSize;
      iIECanvas.Pen.Style := psSolid;
      iIECanvas.Pen.Transparency := iPenAlpha;
      iIECanvas.Pen.Color := iPenAlpha or (iPenAlpha shl 8) or
        (iPenAlpha shl 16);
      iIECanvas.Brush.Style := bsClear;
      iIECanvas.Rectangle(ix1, iy1, ix2, iy2);
      iIECanvas.Free();
      ImageEnView.Update;
      UpdateFrame;
      ImageEnView.IEBitmap.Modified := True;
      ImageEnMView1.IEMBitmap.Modified := True;
    end;
  end;
end;

procedure TForm1.MergeLayers1Click(Sender: TObject);
var
  i: integer;
begin
  if Assigned(PageControl1.ActivePage) then
  begin
    ImageEnView := TImageEnView(PageControl1.ActivePage.Controls[0]);
    if Assigned(ImageEnView) then
    begin
      Screen.Cursor := crHourglass;
      try
        for i := 1 to ImageEnView.LayersCount - 1 do
          ImageEnView.LayersMerge(0, i, True);
        UpdateGUI;
        UpdateLayers;
        UpdateStatusBar;
      finally
        Screen.Cursor := crDefault
      end;
    end;
  end;
end;

procedure TForm1.ImageEnViewMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  iX: Integer;
  iY: Integer;
  iPoint: TPoint;
  iAlpha: Integer;
  iRGB: TRGB;
  iRGBString: string;
  iColor: TColor;
  iisImageLayer: Boolean;
begin
  { Variables for Backbuffer drawing }
  ABX := X;
  ABY := Y;
  { Display X, Y and Opacity }
  iX := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvXScr2Bmp(X);
  iY := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvYScr2Bmp(Y);
  iPoint.X := iX;
  iPoint.Y := iY;
  iisImageLayer := ImageEnView.CurrentLayer is TIEImageLayer;
  if (iisImageLayer) and (iX >= 0) and (iX <= ImageEnView.IEBitmap.Width - 1)
    and (iY >= 0) and (iY <= ImageEnView.IEBitmap.Height - 1) then
  begin
    { Display X, Y position }
    LabelX1.Caption := 'Column: ' + IntegerToString(iX + 1);
    LabelY1.Caption := 'Row: ' + IntegerToString(iY + 1);
     { Get color and alpha }
    if not UseCurrentLayer1.Checked then
      iAlpha := ImageEnView.Layers[0].Bitmap.Alpha[iX, iY]
    else
      iAlpha := ImageEnView.Layers[ImageEnView.LayersCurrent]
        .Bitmap.Alpha[iX, iY];
    if not UseCurrentLayer1.Checked then
      ColorUnderCursor1.Brush.Color :=
        TRGB2TColor(ImageEnView.Layers[0].Bitmap.Pixels[iX, iY])
    else
      ColorUnderCursor1.Brush.Color :=
        TRGB2TColor(ImageEnView.Layers[ImageEnView.LayersCurrent]
        .Bitmap.Pixels[iX, iY]);
    AlphaUnderCursor1.Caption := 'Alpha: ' + IntToStr(iAlpha);
    OpacityUnderCursor1.Caption := 'Opacity: ' +
      IntToStr(IEAlphaToOpacity(iAlpha)) + '%';


After drawing on the added layer with alpha of 151 the layer was merged.
After merging, the alpha of the drawn rectangle is 255. The dithered color
appears to be correct, but the alpha is always 255. All alpha = 0 pixels are 0. All non 0 alpha pixels are now 255.

I can not see anything wrong and the code has always preformed as expected in the past. I emailed you the full project souce.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
xequte Posted - Feb 04 2018 : 21:53:21
Hi Bill

I can't reproduce that. Can you advise the steps to take?

Nigel
Xequte Software
www.imageen.com
w2m Posted - Feb 03 2018 : 11:37:52
In 7.5 LayersMerge is no longer maintaining alpha values. All non 0 alpha values are 255 after merging. Has this changed? I did not see this until recently. As noted it functioned well with alpha channel in the past. Is there another way to achieve this?

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
fab Posted - Apr 16 2012 : 06:20:50
Yes, it is right. Imagine LayersMergeAll as a sort of "rendering" which "applies" alpha channels.
The right way is looping with LayersMerge, even it is a bit slow.