Using AlphaBlend
,
var
Png: TPngImage;
Bmp: TBitmap;
BlendFn: TBlendFunction;
begin
// suppose you already have a master png
Png := TPngImage.Create;
Png.LoadFromFile(
ExtractFilePath(Application.ExeName) + '\..\..\Attention_128.png');
// construct a temporary bitmap with the image
Bmp := TBitmap.Create;
Bmp.Assign(Png);
// prepare TImage for accepting a partial transparent image
Image1.Picture.Bitmap.PixelFormat := pf32bit;
Image1.Picture.Bitmap.AlphaFormat := afPremultiplied;
Image1.Picture.Bitmap.Canvas.Brush.Color := clBlack;
Image1.Picture.Bitmap.SetSize(Png.Width, Png.Height);
// alpha blend the temporary bitmap to the bitmap of the image
BlendFn.BlendOp := AC_SRC_OVER;
BlendFn.BlendFlags := 0;
BlendFn.SourceConstantAlpha := 128; // set opacity here
BlendFn.AlphaFormat := AC_SRC_ALPHA;
winapi.windows.AlphaBlend(Image1.Picture.Bitmap.Canvas.Handle,
0, 0, Image1.Picture.Bitmap.Width, Image1.Picture.Bitmap.Height,
Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, BlendFn);
// free temporary bitmap, etc.
..
Commented a little, the above code produces the below image here (below image is the 'Image1'):