Mirror

How to blend two TBitmap's (Views: 100)


Problem/Question/Abstract:

I need to combine two images: One is a jpeg and the other is a watermark. I have succeeded in placing a jpeg, bmp and gif (converted to bmp) in/ on the image, but I do not not know how to make the watermark image transparent. I want the main jpeg to show through the watermark.

Answer:

The easiest way is using AlphaBlend function, however it works under Win98/ NT/ 2000 only. To make things working under 95 as well you have to implement semitransparency by hands.

{Blend background and foreground bitmaps to get the semitransparency effect}
var
  i, j: Integer;
  BackPoint, ForePoint: pByteArray;
begin
  for i := 0 to FBackGround.Height - 1 do
  begin
    BackPoint := FBackGround.ScanLine[i];
    ForePoint := FForeGround.ScanLine[i];
    for j := 0 to (3 * FBackGround.Width) - 1 do
      ForePoint[j] := ForePoint[j] + Transparency * (BackPoint[j] - ForePoint[j]) div 100;
  end;
end;

Transparency is measured in percents. The size of FBackGround and FForeGround bitmaps should be the same.

<< Back to main page