Problem
I am trying to copy 32x32 tiles from TBitmap to TPaintbox , which is my map editor, but I cannot get transparency to work correctly.
See image below:
Note. For demonstration and testing, I placed TImage under TPaintbox, which will help see if transparency works.

As you can see, the correct tiles are drawn correctly, but the tiles, which should be transparent, are painted on a white background.
Now I use the appropriate classes to manage my maps and fragments, and below, in two ways that I tried to draw:
CopyRect:
procedure TMap.DrawTile(Tileset: TBitmap; MapX, MapY, TileX, TileY: Integer; MapCanvas: TCanvas); begin if TileIsFree(MapX, MapY) then begin MapCanvas.CopyRect( Rect(MapX, MapY, MapX + fTileWidth, MapY + fTileHeight), Tileset.Canvas, Rect(TileX, TileY, TileX + fTileWidth, TileY + fTileHeight)); end; end;
Bitlt
procedure TMap.DrawTile(Tileset: TBitmap; MapX, MapY, TileX, TileY: Integer; MapCanvas: TCanvas); begin if TileIsFree(MapX, MapY) then begin BitBlt( MapCanvas.Handle, MapX, MapY, fTileWidth, fTileHeight, Tileset.Canvas.Handle, TileX, TileY, SRCCOPY); end; end;
I tried to use raster and png image formats for a set of tiles (left image in the screenshot). The only difference between bitmap and png is that CopyRect tries to draw even a few fragments when it is png, but BitBlt manages to draw without any obvious flaws.
Anyway, how to copy / draw a part of TBitmap on TPaintbox without losing transparency or in my case without copying a white background?
Update 1
Following the comments below, I tried calling the AlphaBlend function, but this still leaves unwanted results (note the blue colors around the transparent areas):
procedure TMap.DrawTile(Tileset: Graphics.TBitmap; MapX, MapY, TileX, TileY: Integer; MapCanvas: TCanvas); var BlendFn: TBlendFunction; begin if TileIsFree(MapX, MapY) then begin BlendFn.BlendOp := AC_SRC_OVER; BlendFn.BlendFlags := 0; BlendFn.SourceConstantAlpha := 255; BlendFn.AlphaFormat := AC_SRC_ALPHA; AlphaBlend( MapCanvas.Handle, MapX, MapY, fTileWidth, fTileHeight, Tileset.Canvas.Handle, TileX, TileY, fTileWidth, fTileHeight, BlendFn); end; end;

Thanks.