Board index » delphi » "Merge" two bitmaps

"Merge" two bitmaps

I need to merge two bitmaps and print the resulting one. Unfortunately
Quick Report's image component doesn't support the Transparent
property.

So, are there any routines/components which could be helpfull for me
in that task.

Thanks,
Christian Holzner

 

Re:"Merge" two bitmaps


Quote
Christian Holzner wrote:

> I need to merge two bitmaps and print the resulting one. Unfortunately
> Quick Report's image component doesn't support the Transparent
> property.

> So, are there any routines/components which could be helpfull for me
> in that task.

> Thanks,
> Christian Holzner

Hello Christian,

I recommend to  "merge" bitmaps by creating and ANDMask and an ORMask of
the second bitmap. The ANDMask is a black/white bitmap where all pixels
you want to have transparently must be white and that part you want to
see must be black. The ORMask contains the colored part of your bitmap
and the transparent part in black.
Than you can do something like the following, where Image2 contains the
ANDMask and Image3 the ORMask:

procedure TForm1.Button1Click(Sender: TObject);
begin
  BitBlt(QRImage1.Canvas.Handle, 20, 20, Image2.Width, Image2.Height,
    Image2.Canvas.Handle, 0, 0, SRCAND);        
  BitBlt(QRImage1.Canvas.Handle, 20, 20, Image3.Width, Image3.Height,
    Image3.Canvas.Handle, 0, 0, SRCPAINT);
  QRImage1.Refresh;
end;

{or an OffScreen version}

procedure TForm1.Button1Click(Sender: TObject);
var
  FirstBitmap, ANDMask, ORMask: TBitmap;
begin
  FirstBitmap:= TBitmap.Create;
  ANDMask:= TBitmap.Create;
  ORMask:= TBitmap.Create;
  try
    FirstBitmap.LoadFromFile(''{Path to you first bitmap});
    ANDMask.LoadFromFile(''{Path to you ANDMask});
    ORMask.LoadFromFile(''{Path to you ORMask});
    BitBlt(FirstBitmap.Canvas.Handle, 20, 20, ANDMask.Width,            
      ANDMask.Height, ANDMask.Canvas.Handle, 0, 0, SRCAND);    
    BitBlt(FirstBitmap.Canvas.Handle, 20, 20, ORMask.Width,      
      ORMask.Height, ORMask.Canvas.Handle, 0, 0, SRCPAINT);
    QRImage1.Picture.Bitmap.Assign(FirstBitmap);
  finally
    FirstBitmap.Free;
    ANDMask.Free;
    ORMask.Free;
  end;
end;

For more information look at the Win32API.hlp.

Good luck!

Kerstin

Other Threads