delphigraphicspngdelphi-10.2-tokyowic

TWICImage: How to overlay transparent PNG on JPG?


For example, we have a base image in jpg format:
base jpg base jpg
And the overlay image in png format:
transparent png transparent png
This image I want to get as a result of their merger:
result
My question is: how to get this result using the power of TWICImage?
I can load both images like this:

function DoMerge: TWICImage;
var
  wicJPG,
  wicPNG: TWICImage;
begin
  wicJPG := TWICImage.Create;
  wicPNG := TWICImage.Create;
  try
    wicJPG.LoadFromFile('base.jpg');
    wicPNG.LoadFromFile('overlay.png');
    Result := wicJPG + wicPNG;  // (pseudo-code) how?
  finally
    wicPNG.Free;
    wicJPG.Free;
  end;
end;

Solution

  • I know nothing about TWICImage except that its a TGraphic descendant. So you can try something like this:

    var
      B: TBitmap;
    
    B := TBitmap.Create;
    try
      B.Assign(wicJPG); 
      B.Canvas.Draw(0, 0, wicPNG);
      Result := TWICImage.Create;
      Result.Assign(B);
    finally
      B.Free;
    end;
    

    I can't test it now.